2 * MIO, an I/O abstraction layer replicating C file I/O API.
3 * Copyright (C) 2010 Colomban Wendling <ban@herbesfolles.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* file IO implementation */
31 #define FILE_SET_VTABLE(mio) \
33 mio->v_free = file_free; \
34 mio->v_read = file_read; \
35 mio->v_write = file_write; \
36 mio->v_getc = file_getc; \
37 mio->v_gets = file_gets; \
38 mio->v_ungetc = file_ungetc; \
39 mio->v_putc = file_putc; \
40 mio->v_puts = file_puts; \
41 mio->v_vprintf = file_vprintf; \
42 mio->v_clearerr = file_clearerr; \
43 mio->v_eof = file_eof; \
44 mio->v_error = file_error; \
45 mio->v_seek = file_seek; \
46 mio->v_tell = file_tell; \
47 mio->v_rewind = file_rewind; \
48 mio->v_getpos = file_getpos; \
49 mio->v_setpos = file_setpos; \
56 if (mio
->impl
.file
.close_func
) {
57 mio
->impl
.file
.close_func (mio
->impl
.file
.fp
);
59 mio
->impl
.file
.close_func
= NULL
;
60 mio
->impl
.file
.fp
= NULL
;
69 return fread (ptr
, size
, nmemb
, mio
->impl
.file
.fp
);
78 return fwrite (ptr
, size
, nmemb
, mio
->impl
.file
.fp
);
85 return fputc (c
, mio
->impl
.file
.fp
);
92 return fputs (s
, mio
->impl
.file
.fp
);
96 file_vprintf (MIO
*mio
,
100 return vfprintf (mio
->impl
.file
.fp
, format
, ap
);
106 return fgetc (mio
->impl
.file
.fp
);
110 file_ungetc (MIO
*mio
,
113 return ungetc (ch
, mio
->impl
.file
.fp
);
121 return fgets (s
, (int)size
, mio
->impl
.file
.fp
);
125 file_clearerr (MIO
*mio
)
127 clearerr (mio
->impl
.file
.fp
);
133 return feof (mio
->impl
.file
.fp
);
137 file_error (MIO
*mio
)
139 return ferror (mio
->impl
.file
.fp
);
147 return fseek (mio
->impl
.file
.fp
, offset
, whence
);
153 return ftell (mio
->impl
.file
.fp
);
157 file_rewind (MIO
*mio
)
159 rewind (mio
->impl
.file
.fp
);
163 file_getpos (MIO
*mio
,
166 return fgetpos (mio
->impl
.file
.fp
, &pos
->impl
.file
);
170 file_setpos (MIO
*mio
,
173 return fsetpos (mio
->impl
.file
.fp
, &pos
->impl
.file
);