OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * 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 struct NaClDesc *wrapped) { | |
20 self->wrapped = NaClDescRef(wrapped); | |
21 NACL_VTBL(Gio, self) = &kNaClGioNaClDescVtbl; | |
22 return 1; | |
23 } | |
24 | |
25 static ssize_t NaClGioNaClDescRead(struct Gio *vself, | |
26 void *buf, | |
27 size_t count) { | |
28 struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself; | |
29 | |
30 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 size_t count) { | |
37 struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself; | |
38 | |
39 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 int whence) { | |
46 struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself; | |
47 | |
48 return (off_t) (*NACL_VTBL(NaClDesc, self->wrapped)-> | |
49 Seek)(self->wrapped, (nacl_off64_t) offset, whence); | |
50 } | |
51 | |
52 static int NaClGioNaClDescFlush(struct Gio *vself) { | |
53 UNREFERENCED_PARAMETER(vself); | |
54 return 0; | |
55 } | |
56 | |
57 static int NaClGioNaClDescClose(struct Gio *vself) { | |
58 struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself; | |
59 | |
60 NaClDescUnref(self->wrapped); | |
61 self->wrapped = 0; | |
62 return 0; | |
63 } | |
64 | |
65 static void NaClGioNaClDescDtor(struct Gio *vself) { | |
66 struct NaClGioNaClDesc *self = (struct NaClGioNaClDesc *) vself; | |
67 | |
68 if (NULL != self->wrapped) { | |
69 NaClDescUnref(self->wrapped); | |
70 self->wrapped = 0; | |
71 } | |
72 NACL_VTBL(Gio, self) = NULL; | |
73 /* Gio base class has no Dtor */ | |
74 } | |
75 | |
76 const struct GioVtbl kNaClGioNaClDescVtbl = { | |
77 NaClGioNaClDescDtor, | |
78 NaClGioNaClDescRead, | |
79 NaClGioNaClDescWrite, | |
80 NaClGioNaClDescSeek, | |
81 NaClGioNaClDescFlush, | |
82 NaClGioNaClDescClose, | |
83 }; | |
OLD | NEW |