1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 :
7 : #include "native_client/src/include/portability.h"
8 :
9 : #include "native_client/src/shared/platform/nacl_check.h"
10 : #include "native_client/src/shared/platform/nacl_log.h"
11 :
12 : #include "native_client/src/trusted/gio/gio_nacl_desc.h"
13 :
14 : #include "native_client/src/trusted/desc/nacl_desc_base.h"
15 :
16 : const struct GioVtbl kNaClGioNaClDescVtbl;
17 :
18 : int NaClGioNaClDescCtor(struct NaClGioNaClDesc *self,
19 3 : struct NaClDesc *wrapped) {
20 3 : self->wrapped = NaClDescRef(wrapped);
21 3 : NACL_VTBL(Gio, self) = &kNaClGioNaClDescVtbl;
22 3 : return 1;
23 : }
24 :
25 : static ssize_t NaClGioNaClDescRead(struct Gio *vself,
26 : void *buf,
27 103 : size_t count) {
28 103 : struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself;
29 :
30 103 : return (*NACL_VTBL(NaClDesc, self->wrapped)->
31 : Read)(self->wrapped, buf, count);
32 : }
33 :
34 : static ssize_t NaClGioNaClDescWrite(struct Gio *vself,
35 : void const *buf,
36 102 : size_t count) {
37 102 : struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself;
38 :
39 102 : return (*NACL_VTBL(NaClDesc, self->wrapped)->
40 : Write)(self->wrapped, buf, count);
41 : }
42 :
43 : static off_t NaClGioNaClDescSeek(struct Gio *vself,
44 : off_t offset,
45 138 : int whence) {
46 138 : struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself;
47 :
48 138 : return (off_t) (*NACL_VTBL(NaClDesc, self->wrapped)->
49 : Seek)(self->wrapped, (nacl_off64_t) offset, whence);
50 : }
51 :
52 0 : static int NaClGioNaClDescFlush(struct Gio *vself) {
53 : UNREFERENCED_PARAMETER(vself);
54 0 : return 0;
55 : }
56 :
57 3 : static int NaClGioNaClDescClose(struct Gio *vself) {
58 3 : struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself;
59 :
60 3 : NaClDescUnref(self->wrapped);
61 3 : self->wrapped = 0;
62 3 : return 0;
63 : }
64 :
65 3 : static void NaClGioNaClDescDtor(struct Gio *vself) {
66 3 : struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself;
67 :
68 3 : if (NULL != self->wrapped) {
69 0 : NaClDescUnref(self->wrapped);
70 0 : self->wrapped = 0;
71 : }
72 3 : NACL_VTBL(Gio, self) = NULL;
73 : /* Gio base class has no Dtor */
74 3 : }
75 :
76 : const struct GioVtbl kNaClGioNaClDescVtbl = {
77 : NaClGioNaClDescRead,
78 : NaClGioNaClDescWrite,
79 : NaClGioNaClDescSeek,
80 : NaClGioNaClDescFlush,
81 : NaClGioNaClDescClose,
82 : NaClGioNaClDescDtor,
83 : };
|