forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mio.h
162 lines (142 loc) · 4.28 KB
/
mio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* MIO, an I/O abstraction layer replicating C file I/O API.
* Copyright (C) 2010 Colomban Wendling <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifndef MIO_H
#define MIO_H
#ifndef QUALIFIER
#include "general.h" /* must always come first */
#else
#include "gcc-attr.h"
#endif
#include <stdio.h>
#include <stdarg.h>
/**
* MIOType:
* @MIO_TYPE_FILE: #MIO object works on a file
* @MIO_TYPE_MEMORY: #MIO object works in-memory
*
* Existing implementations.
*/
enum _MIOType {
MIO_TYPE_FILE,
MIO_TYPE_MEMORY
};
typedef enum _MIOType MIOType;
typedef struct _MIO MIO;
typedef struct _MIOPos MIOPos;
/**
* MIOReallocFunc:
* @ptr: Pointer to the memory to resize
* @size: New size of the memory pointed by @ptr
*
* A function following the realloc() semantic.
*
* Returns: A pointer to the start of the new memory, or %NULL on failure.
*/
typedef void *(* MIOReallocFunc) (void * ptr, size_t size);
/**
* MIOFOpenFunc:
* @filename: The filename to open
* @mode: fopen() modes for opening @filename
*
* A function following the fclose() semantic, used to close a #FILE
* object.
*
* Returns: A new #FILE object, or %NULL on failure
*/
typedef FILE *(* MIOFOpenFunc) (const char *filename, const char *mode);
/**
* MIOFCloseFunc:
* @fp: An opened #FILE object
*
* A function following the fclose() semantic, used to close a #FILE
* object.
*
* Returns: 0 on success, EOF otherwise.
*/
typedef int (* MIOFCloseFunc) (FILE *fp);
/**
* MIODestroyNotify:
* @data: Data element being destroyed
*
* Specifies the type of function which is called when a data element is
* destroyed. It is passed the pointer to the data element and should free any
* memory and resources allocated for it.
*/
typedef void (*MIODestroyNotify) (void *data);
/**
* MIOPos:
*
* An object representing the state of a #MIO stream. This object can be
* statically allocated but all its fields are private and should not be
* accessed directly.
*/
struct _MIOPos {
/*< private >*/
MIOType type;
#ifdef MIO_DEBUG
void *tag;
#endif
union {
fpos_t file;
size_t mem;
} impl;
};
MIO *mio_new_file (const char *filename, const char *mode);
MIO *mio_new_file_full (const char *filename,
const char *mode,
MIOFOpenFunc open_func,
MIOFCloseFunc close_func);
MIO *mio_new_fp (FILE *fp, MIOFCloseFunc close_func);
MIO *mio_new_memory (unsigned char *data,
size_t size,
MIOReallocFunc realloc_func,
MIODestroyNotify free_func);
MIO *mio_new_mio (MIO *base, long start, long size);
MIO *mio_ref (MIO *mio);
int mio_unref (MIO *mio);
FILE *mio_file_get_fp (MIO *mio);
unsigned char *mio_memory_get_data (MIO *mio, size_t *size);
size_t mio_read (MIO *mio,
void *ptr,
size_t size,
size_t nmemb);
size_t mio_write (MIO *mio,
const void *ptr,
size_t size,
size_t nmemb);
int mio_getc (MIO *mio);
char *mio_gets (MIO *mio, char *s, size_t size);
int mio_ungetc (MIO *mio, int ch);
int mio_putc (MIO *mio, int c);
int mio_puts (MIO *mio, const char *s);
int mio_vprintf (MIO *mio, const char *format, va_list ap) CTAGS_ATTR_PRINTF (2, 0);
int mio_printf (MIO *mio, const char *format, ...) CTAGS_ATTR_PRINTF (2, 3);
void mio_clearerr (MIO *mio);
int mio_eof (MIO *mio);
int mio_error (MIO *mio);
int mio_seek (MIO *mio, long offset, int whence);
long mio_tell (MIO *mio);
void mio_rewind (MIO *mio);
int mio_getpos (MIO *mio, MIOPos *pos);
int mio_setpos (MIO *mio, MIOPos *pos);
int mio_flush (MIO *mio);
void mio_attach_user_data (MIO *mio, void *user_data, MIODestroyNotify user_data_free_func);
void *mio_get_user_data (MIO *mio);
#endif /* MIO_H */