Merge branch 'freebasic-ft-update'
[geany-mirror.git] / tagmanager / mio / mio-file.c
blobc19914f341986e4b6d4779bf422500651c84cb85
1 /*
2 * MIO, an I/O abstraction layer replicating C file I/O API.
3 * Copyright (C) 2010 Colomban Wendling <ban@herbesfolles.org>
4 *
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.
9 *
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 */
23 #include <glib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <errno.h>
28 #include "mio.h"
31 #define FILE_SET_VTABLE(mio) \
32 G_STMT_START { \
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; \
50 } G_STMT_END
53 static void
54 file_free (MIO *mio)
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;
63 static gsize
64 file_read (MIO *mio,
65 void *ptr,
66 gsize size,
67 gsize nmemb)
69 return fread (ptr, size, nmemb, mio->impl.file.fp);
72 static gsize
73 file_write (MIO *mio,
74 const void *ptr,
75 gsize size,
76 gsize nmemb)
78 return fwrite (ptr, size, nmemb, mio->impl.file.fp);
81 static gint
82 file_putc (MIO *mio,
83 gint c)
85 return fputc (c, mio->impl.file.fp);
88 static gint
89 file_puts (MIO *mio,
90 const gchar *s)
92 return fputs (s, mio->impl.file.fp);
95 static gint
96 file_vprintf (MIO *mio,
97 const gchar *format,
98 va_list ap)
100 return vfprintf (mio->impl.file.fp, format, ap);
103 static gint
104 file_getc (MIO *mio)
106 return fgetc (mio->impl.file.fp);
109 static gint
110 file_ungetc (MIO *mio,
111 gint ch)
113 return ungetc (ch, mio->impl.file.fp);
116 static gchar *
117 file_gets (MIO *mio,
118 gchar *s,
119 gsize size)
121 return fgets (s, (int)size, mio->impl.file.fp);
124 static void
125 file_clearerr (MIO *mio)
127 clearerr (mio->impl.file.fp);
130 static gint
131 file_eof (MIO *mio)
133 return feof (mio->impl.file.fp);
136 static gint
137 file_error (MIO *mio)
139 return ferror (mio->impl.file.fp);
142 static gint
143 file_seek (MIO *mio,
144 glong offset,
145 gint whence)
147 return fseek (mio->impl.file.fp, offset, whence);
150 static glong
151 file_tell (MIO *mio)
153 return ftell (mio->impl.file.fp);
156 static void
157 file_rewind (MIO *mio)
159 rewind (mio->impl.file.fp);
162 static gint
163 file_getpos (MIO *mio,
164 MIOPos *pos)
166 return fgetpos (mio->impl.file.fp, &pos->impl.file);
169 static gint
170 file_setpos (MIO *mio,
171 MIOPos *pos)
173 return fsetpos (mio->impl.file.fp, &pos->impl.file);