2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl Generic I/O interface.
36 #ifndef SERVICE_RUNTIME_GIO_H__
37 #define SERVICE_RUNTIME_GIO_H__ 1
39 /* is this needed? - maybe for size_t */
40 #include "native_client/include/portability.h"
52 int (*Read
)(struct Gio
*vself
,
54 size_t count
); /* returns nbytes read */
55 int (*Write
)(struct Gio
*vself
,
57 size_t count
); /* returns nbytes written */
58 off_t (*Seek
)(struct Gio
*vself
,
60 int whence
); /* returns -1 on error */
61 int (*Flush
)(struct Gio
*vself
); /* only used for write */
62 int (*Close
)(struct Gio
*vself
); /* returns -1 on error */
63 void (*Dtor
)(struct Gio
*vself
); /* implicit close */
67 struct GioVtbl
const *vtbl
;
75 int GioFileCtor(struct GioFile
*self
,
79 int GioFileRead(struct Gio
*vself
,
83 int GioFileWrite(struct Gio
*vself
,
87 off_t
GioFileSeek(struct Gio
*vself
,
91 int GioFileFlush(struct Gio
*vself
);
93 int GioFileClose(struct Gio
*vself
);
95 void GioFileDtor(struct Gio
*vself
);
97 int GioFileRefCtor(struct GioFile
*self
,
100 struct GioMemoryFile
{
105 /* invariant: 0 <= curpos && curpos <= len */
106 /* if curpos == len, everything has been read */
109 int GioMemoryFileCtor(struct GioMemoryFile
*self
,
113 int GioMemoryFileRead(struct Gio
*vself
,
117 int GioMemoryFileWrite(struct Gio
*vself
,
121 off_t
GioMemoryFileSeek(struct Gio
*vself
,
125 int GioMemoryFileFlush(struct Gio
*vself
);
127 int GioMemoryFileClose(struct Gio
*vself
);
129 void GioMemoryFileDtor(struct Gio
*vself
);
131 struct GioMemoryFileSnapshot
{
132 struct GioMemoryFile base
;
135 int GioMemoryFileSnapshotCtor(struct GioMemoryFileSnapshot
*self
,
138 void GioMemoryFileSnapshotDtor(struct Gio
*vself
);
140 #define ggetc(gp) ({ char ch; (*gp->vtbl->Read)(gp, &ch, 1) == 1 ? ch : EOF;})
142 int fggetc(struct Gio
*gp
);
144 int gprintf(struct Gio
*gp
,
148 int gvprintf(struct Gio
*gp
,
153 } /* end of extern "C" */