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.
31 * @MIO_TYPE_FILE: #MIO object works on a file
32 * @MIO_TYPE_MEMORY: #MIO object works in-memory
34 * Existing implementations.
41 typedef enum _MIOType MIOType
;
42 typedef struct _MIO MIO
;
43 typedef struct _MIOPos MIOPos
;
46 * @ptr: Pointer to the memory to resize
47 * @size: New size of the memory pointed by @ptr
49 * A function following the realloc() semantic.
51 * Returns: A pointer to the start of the new memory, or %NULL on failure.
53 /* should be GReallocFunc but it's only defined by GIO */
54 typedef gpointer (* MIOReallocFunc
) (gpointer ptr
,
59 * @filename: The filename to open
60 * @mode: fopen() modes for opening @filename
62 * A function following the fclose() semantic, used to close a #FILE
65 * Returns: A new #FILE object, or %NULL on failure
67 typedef FILE *(* MIOFOpenFunc
) (const gchar
*filename
,
72 * @fp: An opened #FILE object
74 * A function following the fclose() semantic, used to close a #FILE
77 * Returns: 0 on success, EOF otherwise.
79 typedef gint (* MIOFCloseFunc
) (FILE *fp
);
84 * An object representing the state of a #MIO stream. This object can be
85 * statically allocated but all its fields are private and should not be
103 * An object representing a #MIO stream. No assumptions should be made about
104 * what compose this object, and none of its fields should be accessed directly.
112 MIOFCloseFunc close_func
;
119 gsize allocated_size
;
120 MIOReallocFunc realloc_func
;
121 GDestroyNotify free_func
;
126 /* virtual function table */
127 void (*v_free
) (MIO
*mio
);
128 gsize (*v_read
) (MIO
*mio
,
132 gsize (*v_write
) (MIO
*mio
,
136 gint (*v_getc
) (MIO
*mio
);
137 gchar
*(*v_gets
) (MIO
*mio
,
140 gint (*v_ungetc
) (MIO
*mio
,
142 gint (*v_putc
) (MIO
*mio
,
144 gint (*v_puts
) (MIO
*mio
,
146 gint (*v_vprintf
) (MIO
*mio
,
148 va_list ap
) G_GNUC_PRINTF (2, 0);
149 void (*v_clearerr
) (MIO
*mio
);
150 gint (*v_eof
) (MIO
*mio
);
151 gint (*v_error
) (MIO
*mio
);
152 gint (*v_seek
) (MIO
*mio
,
155 glong (*v_tell
) (MIO
*mio
);
156 void (*v_rewind
) (MIO
*mio
);
157 gint (*v_getpos
) (MIO
*mio
,
159 gint (*v_setpos
) (MIO
*mio
,
164 MIO
*mio_new_file (const gchar
*filename
,
166 MIO
*mio_new_file_full (const gchar
*filename
,
168 MIOFOpenFunc open_func
,
169 MIOFCloseFunc close_func
);
170 MIO
*mio_new_fp (FILE *fp
,
171 MIOFCloseFunc close_func
);
172 MIO
*mio_new_memory (guchar
*data
,
174 MIOReallocFunc realloc_func
,
175 GDestroyNotify free_func
);
176 void mio_free (MIO
*mio
);
177 FILE *mio_file_get_fp (MIO
*mio
);
178 guchar
*mio_memory_get_data (MIO
*mio
,
180 gsize
mio_read (MIO
*mio
,
184 gsize
mio_write (MIO
*mio
,
188 gint
mio_getc (MIO
*mio
);
189 gchar
*mio_gets (MIO
*mio
,
192 gint
mio_ungetc (MIO
*mio
,
194 gint
mio_putc (MIO
*mio
,
196 gint
mio_puts (MIO
*mio
,
199 gint
mio_vprintf (MIO
*mio
,
201 va_list ap
) G_GNUC_PRINTF (2, 0);
202 gint
mio_printf (MIO
*mio
,
204 ...) G_GNUC_PRINTF (2, 3);
206 void mio_clearerr (MIO
*mio
);
207 gint
mio_eof (MIO
*mio
);
208 gint
mio_error (MIO
*mio
);
209 gint
mio_seek (MIO
*mio
,
212 glong
mio_tell (MIO
*mio
);
213 void mio_rewind (MIO
*mio
);
214 gint
mio_getpos (MIO
*mio
,
216 gint
mio_setpos (MIO
*mio
,