]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 1993-2015 Free Software Foundation, Inc. |
41bdb6e2 | 2 | This file is part of the GNU C Library. |
40a55d20 | 3 | |
41bdb6e2 AJ |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
40a55d20 | 8 | |
41bdb6e2 AJ |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
40a55d20 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41bdb6e2 AJ |
12 | Lesser General Public License for more details. |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. | |
41bdb6e2 AJ |
17 | |
18 | As a special exception, if you link the code in this file with | |
19 | files compiled with a GNU compiler to produce an executable, | |
20 | that does not cause the resulting executable to be covered by | |
21 | the GNU Lesser General Public License. This exception does not | |
22 | however invalidate any other reasons why the executable file | |
23 | might be covered by the GNU Lesser General Public License. | |
24 | This exception applies to code released by its copyright holders | |
25 | in files containing the exception. */ | |
96aa2d94 | 26 | |
b1848fde SP |
27 | /* NOTE: libio is now exclusively used only by glibc since libstdc++ has its |
28 | own implementation. As a result, functions that were implemented for C++ | |
29 | (like *sputn) may no longer have C++ semantics. This is of course only | |
30 | relevant for internal callers of these functions since these functions are | |
31 | not intended for external use otherwise. | |
32 | ||
33 | FIXME: All of the C++ cruft eventually needs to go away. */ | |
34 | ||
96aa2d94 | 35 | #include <errno.h> |
a2b08ee5 UD |
36 | #ifndef __set_errno |
37 | # define __set_errno(Val) errno = (Val) | |
38 | #endif | |
39 | #if defined __GLIBC__ && __GLIBC__ >= 2 | |
40 | # include <bits/libc-lock.h> | |
41 | #else | |
42 | /*# include <comthread.h>*/ | |
43 | #endif | |
96aa2d94 | 44 | |
c6251f03 RM |
45 | #include <math_ldbl_opt.h> |
46 | ||
96aa2d94 RM |
47 | #include "iolibio.h" |
48 | ||
77fe0b9c UD |
49 | /* Control of exported symbols. Used in glibc. By default we don't |
50 | do anything. */ | |
37ba7d66 UD |
51 | #ifndef libc_hidden_proto |
52 | # define libc_hidden_proto(name) | |
53 | #endif | |
54 | #ifndef libc_hidden_def | |
55 | # define libc_hidden_def(name) | |
56 | #endif | |
57 | #ifndef libc_hidden_weak | |
58 | # define libc_hidden_weak(name) | |
59 | #endif | |
60 | ||
4547c1a4 UD |
61 | #ifdef __cplusplus |
62 | extern "C" { | |
63 | #endif | |
96aa2d94 RM |
64 | |
65 | #define _IO_seek_set 0 | |
66 | #define _IO_seek_cur 1 | |
67 | #define _IO_seek_end 2 | |
68 | ||
f65fd747 UD |
69 | /* THE JUMPTABLE FUNCTIONS. |
70 | ||
71 | * The _IO_FILE type is used to implement the FILE type in GNU libc, | |
72 | * as well as the streambuf class in GNU iostreams for C++. | |
73 | * These are all the same, just used differently. | |
74 | * An _IO_FILE (or FILE) object is allows followed by a pointer to | |
75 | * a jump table (of pointers to functions). The pointer is accessed | |
c0c3f78a | 76 | * with the _IO_JUMPS macro. The jump table has an eccentric format, |
f65fd747 | 77 | * so as to be compatible with the layout of a C++ virtual function table. |
6d52618b | 78 | * (as implemented by g++). When a pointer to a streambuf object is |
f65fd747 UD |
79 | * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just |
80 | * happens to point to the virtual function table of the streambuf. | |
81 | * Thus the _IO_JUMPS function table used for C stdio/libio does | |
6d52618b | 82 | * double duty as the virtual function table for C++ streambuf. |
f65fd747 UD |
83 | * |
84 | * The entries in the _IO_JUMPS function table (and hence also the | |
85 | * virtual functions of a streambuf) are described below. | |
86 | * The first parameter of each function entry is the _IO_FILE/streambuf | |
87 | * object being acted on (i.e. the 'this' parameter). | |
88 | */ | |
96aa2d94 | 89 | |
00404a96 RM |
90 | #ifdef _LIBC |
91 | # include <shlib-compat.h> | |
92 | # if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) | |
93 | /* Setting this macro disables the use of the _vtable_offset | |
94 | bias in _IO_JUMPS_FUNCS, below. That is only needed if we | |
95 | want to support old binaries (see oldfileops.c). */ | |
96 | # define _G_IO_NO_BACKWARD_COMPAT 1 | |
97 | # endif | |
98 | #endif | |
99 | ||
bd355af0 UD |
100 | #if (!defined _IO_USE_OLD_IO_FILE \ |
101 | && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0)) | |
102 | # define _IO_JUMPS_OFFSET 1 | |
8f2f08d0 RM |
103 | #else |
104 | # define _IO_JUMPS_OFFSET 0 | |
bd355af0 UD |
105 | #endif |
106 | ||
2ca8b1ee | 107 | #define _IO_JUMPS(THIS) (THIS)->vtable |
d64b6ad0 | 108 | #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable |
7163e69e UD |
109 | #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL) |
110 | ||
c15cf13a | 111 | #if _IO_JUMPS_OFFSET |
bd355af0 | 112 | # define _IO_JUMPS_FUNC(THIS) \ |
2ca8b1ee | 113 | (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \ |
bd355af0 | 114 | + (THIS)->_vtable_offset)) |
bbdef797 | 115 | # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset |
bd355af0 | 116 | #else |
2ca8b1ee | 117 | # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) |
bbdef797 | 118 | # define _IO_vtable_offset(THIS) 0 |
bd355af0 | 119 | #endif |
6e06ae59 | 120 | #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS) |
28361c5e JM |
121 | #define JUMP_FIELD(TYPE, NAME) TYPE NAME |
122 | #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS) | |
123 | #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1) | |
124 | #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2) | |
125 | #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3) | |
126 | #define JUMP_INIT(NAME, VALUE) VALUE | |
127 | #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0) | |
128 | ||
129 | #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS) | |
130 | #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1) | |
131 | #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2) | |
132 | #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3) | |
96aa2d94 | 133 | |
f65fd747 | 134 | /* The 'finish' function does any final cleaning up of an _IO_FILE object. |
110215a9 | 135 | It does not delete (free) it, but does everything else to finalize it. |
f65fd747 | 136 | It matches the streambuf::~streambuf virtual destructor. */ |
79937577 | 137 | typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */ |
40a55d20 | 138 | #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0) |
6e06ae59 | 139 | #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0) |
f65fd747 UD |
140 | |
141 | /* The 'overflow' hook flushes the buffer. | |
142 | The second argument is a character, or EOF. | |
143 | It matches the streambuf::overflow virtual function. */ | |
79937577 | 144 | typedef int (*_IO_overflow_t) (_IO_FILE *, int); |
40a55d20 | 145 | #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH) |
6e06ae59 | 146 | #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH) |
f65fd747 UD |
147 | |
148 | /* The 'underflow' hook tries to fills the get buffer. | |
149 | It returns the next character (as an unsigned char) or EOF. The next | |
6d52618b | 150 | character remains in the get buffer, and the get position is not changed. |
f65fd747 | 151 | It matches the streambuf::underflow virtual function. */ |
79937577 | 152 | typedef int (*_IO_underflow_t) (_IO_FILE *); |
40a55d20 | 153 | #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP) |
6e06ae59 | 154 | #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP) |
f65fd747 UD |
155 | |
156 | /* The 'uflow' hook returns the next character in the input stream | |
157 | (cast to unsigned char), and increments the read position; | |
158 | EOF is returned on failure. | |
159 | It matches the streambuf::uflow virtual function, which is not in the | |
160 | cfront implementation, but was added to C++ by the ANSI/ISO committee. */ | |
40a55d20 | 161 | #define _IO_UFLOW(FP) JUMP0 (__uflow, FP) |
6e06ae59 | 162 | #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP) |
f65fd747 UD |
163 | |
164 | /* The 'pbackfail' hook handles backing up. | |
165 | It matches the streambuf::pbackfail virtual function. */ | |
79937577 | 166 | typedef int (*_IO_pbackfail_t) (_IO_FILE *, int); |
40a55d20 | 167 | #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH) |
6e06ae59 | 168 | #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH) |
f65fd747 UD |
169 | |
170 | /* The 'xsputn' hook writes upto N characters from buffer DATA. | |
2b766585 | 171 | Returns EOF or the number of character actually written. |
f65fd747 | 172 | It matches the streambuf::xsputn virtual function. */ |
79937577 UD |
173 | typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA, |
174 | _IO_size_t N); | |
40a55d20 | 175 | #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N) |
6e06ae59 | 176 | #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N) |
f65fd747 UD |
177 | |
178 | /* The 'xsgetn' hook reads upto N characters into buffer DATA. | |
179 | Returns the number of character actually read. | |
180 | It matches the streambuf::xsgetn virtual function. */ | |
79937577 | 181 | typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N); |
40a55d20 | 182 | #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N) |
6e06ae59 | 183 | #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N) |
f65fd747 UD |
184 | |
185 | /* The 'seekoff' hook moves the stream position to a new position | |
186 | relative to the start of the file (if DIR==0), the current position | |
187 | (MODE==1), or the end of the file (MODE==2). | |
188 | It matches the streambuf::seekoff virtual function. | |
189 | It is also used for the ANSI fseek function. */ | |
79937577 UD |
190 | typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR, |
191 | int MODE); | |
40a55d20 | 192 | #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE) |
6e06ae59 | 193 | #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE) |
f65fd747 UD |
194 | |
195 | /* The 'seekpos' hook also moves the stream position, | |
dfd2257a | 196 | but to an absolute position given by a fpos64_t (seekpos). |
f65fd747 UD |
197 | It matches the streambuf::seekpos virtual function. |
198 | It is also used for the ANSI fgetpos and fsetpos functions. */ | |
199 | /* The _IO_seek_cur and _IO_seek_end options are not allowed. */ | |
79937577 | 200 | typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int); |
40a55d20 | 201 | #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS) |
6e06ae59 | 202 | #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS) |
f65fd747 UD |
203 | |
204 | /* The 'setbuf' hook gives a buffer to the file. | |
205 | It matches the streambuf::setbuf virtual function. */ | |
79937577 | 206 | typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t); |
40a55d20 | 207 | #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH) |
6e06ae59 | 208 | #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH) |
f65fd747 UD |
209 | |
210 | /* The 'sync' hook attempts to synchronize the internal data structures | |
211 | of the file with the external state. | |
212 | It matches the streambuf::sync virtual function. */ | |
79937577 | 213 | typedef int (*_IO_sync_t) (_IO_FILE *); |
40a55d20 | 214 | #define _IO_SYNC(FP) JUMP0 (__sync, FP) |
6e06ae59 | 215 | #define _IO_WSYNC(FP) WJUMP0 (__sync, FP) |
f65fd747 UD |
216 | |
217 | /* The 'doallocate' hook is used to tell the file to allocate a buffer. | |
218 | It matches the streambuf::doallocate virtual function, which is not | |
219 | in the ANSI/ISO C++ standard, but is part traditional implementations. */ | |
79937577 | 220 | typedef int (*_IO_doallocate_t) (_IO_FILE *); |
40a55d20 | 221 | #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP) |
6e06ae59 | 222 | #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP) |
f65fd747 UD |
223 | |
224 | /* The following four hooks (sysread, syswrite, sysclose, sysseek, and | |
225 | sysstat) are low-level hooks specific to this implementation. | |
6d52618b | 226 | There is no correspondence in the ANSI/ISO C++ standard library. |
f65fd747 UD |
227 | The hooks basically correspond to the Unix system functions |
228 | (read, write, close, lseek, and stat) except that a _IO_FILE* | |
c0c3f78a | 229 | parameter is used instead of an integer file descriptor; the default |
f65fd747 UD |
230 | implementation used for normal files just calls those functions. |
231 | The advantage of overriding these functions instead of the higher-level | |
232 | ones (underflow, overflow etc) is that you can leave all the buffering | |
233 | higher-level functions. */ | |
234 | ||
235 | /* The 'sysread' hook is used to read data from the external file into | |
236 | an existing buffer. It generalizes the Unix read(2) function. | |
237 | It matches the streambuf::sys_read virtual function, which is | |
6d52618b | 238 | specific to this implementation. */ |
79937577 | 239 | typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t); |
40a55d20 | 240 | #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN) |
6e06ae59 | 241 | #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN) |
f65fd747 UD |
242 | |
243 | /* The 'syswrite' hook is used to write data from an existing buffer | |
244 | to an external file. It generalizes the Unix write(2) function. | |
245 | It matches the streambuf::sys_write virtual function, which is | |
6d52618b | 246 | specific to this implementation. */ |
79937577 | 247 | typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t); |
40a55d20 | 248 | #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN) |
6e06ae59 | 249 | #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN) |
f65fd747 UD |
250 | |
251 | /* The 'sysseek' hook is used to re-position an external file. | |
252 | It generalizes the Unix lseek(2) function. | |
253 | It matches the streambuf::sys_seek virtual function, which is | |
6d52618b | 254 | specific to this implementation. */ |
79937577 | 255 | typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int); |
40a55d20 | 256 | #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE) |
6e06ae59 | 257 | #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE) |
f65fd747 UD |
258 | |
259 | /* The 'sysclose' hook is used to finalize (close, finish up) an | |
260 | external file. It generalizes the Unix close(2) function. | |
261 | It matches the streambuf::sys_close virtual function, which is | |
262 | specific to this implementation. */ | |
79937577 | 263 | typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */ |
40a55d20 | 264 | #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP) |
6e06ae59 | 265 | #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP) |
f65fd747 UD |
266 | |
267 | /* The 'sysstat' hook is used to get information about an external file | |
268 | into a struct stat buffer. It generalizes the Unix fstat(2) call. | |
269 | It matches the streambuf::sys_stat virtual function, which is | |
6d52618b | 270 | specific to this implementation. */ |
79937577 | 271 | typedef int (*_IO_stat_t) (_IO_FILE *, void *); |
40a55d20 | 272 | #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF) |
6e06ae59 | 273 | #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF) |
96aa2d94 | 274 | |
dfd2257a UD |
275 | /* The 'showmany' hook can be used to get an image how much input is |
276 | available. In many cases the answer will be 0 which means unknown | |
277 | but some cases one can provide real information. */ | |
79937577 | 278 | typedef int (*_IO_showmanyc_t) (_IO_FILE *); |
dfd2257a | 279 | #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP) |
6e06ae59 | 280 | #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP) |
dfd2257a UD |
281 | |
282 | /* The 'imbue' hook is used to get information about the currently | |
283 | installed locales. */ | |
79937577 | 284 | typedef void (*_IO_imbue_t) (_IO_FILE *, void *); |
dfd2257a | 285 | #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE) |
6e06ae59 | 286 | #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE) |
dfd2257a | 287 | |
f65fd747 | 288 | |
96aa2d94 RM |
289 | #define _IO_CHAR_TYPE char /* unsigned char ? */ |
290 | #define _IO_INT_TYPE int | |
291 | ||
40a55d20 UD |
292 | struct _IO_jump_t |
293 | { | |
203e5603 JM |
294 | JUMP_FIELD(size_t, __dummy); |
295 | JUMP_FIELD(size_t, __dummy2); | |
96aa2d94 RM |
296 | JUMP_FIELD(_IO_finish_t, __finish); |
297 | JUMP_FIELD(_IO_overflow_t, __overflow); | |
298 | JUMP_FIELD(_IO_underflow_t, __underflow); | |
299 | JUMP_FIELD(_IO_underflow_t, __uflow); | |
300 | JUMP_FIELD(_IO_pbackfail_t, __pbackfail); | |
301 | /* showmany */ | |
302 | JUMP_FIELD(_IO_xsputn_t, __xsputn); | |
303 | JUMP_FIELD(_IO_xsgetn_t, __xsgetn); | |
304 | JUMP_FIELD(_IO_seekoff_t, __seekoff); | |
305 | JUMP_FIELD(_IO_seekpos_t, __seekpos); | |
306 | JUMP_FIELD(_IO_setbuf_t, __setbuf); | |
307 | JUMP_FIELD(_IO_sync_t, __sync); | |
308 | JUMP_FIELD(_IO_doallocate_t, __doallocate); | |
309 | JUMP_FIELD(_IO_read_t, __read); | |
310 | JUMP_FIELD(_IO_write_t, __write); | |
311 | JUMP_FIELD(_IO_seek_t, __seek); | |
312 | JUMP_FIELD(_IO_close_t, __close); | |
313 | JUMP_FIELD(_IO_stat_t, __stat); | |
dfd2257a UD |
314 | JUMP_FIELD(_IO_showmanyc_t, __showmanyc); |
315 | JUMP_FIELD(_IO_imbue_t, __imbue); | |
96aa2d94 RM |
316 | #if 0 |
317 | get_column; | |
318 | set_column; | |
319 | #endif | |
320 | }; | |
321 | ||
322 | /* We always allocate an extra word following an _IO_FILE. | |
f65fd747 | 323 | This contains a pointer to the function jump table used. |
96aa2d94 RM |
324 | This is for compatibility with C++ streambuf; the word can |
325 | be used to smash to a pointer to a virtual function table. */ | |
326 | ||
40a55d20 UD |
327 | struct _IO_FILE_plus |
328 | { | |
96aa2d94 | 329 | _IO_FILE file; |
96aa2d94 | 330 | const struct _IO_jump_t *vtable; |
96aa2d94 RM |
331 | }; |
332 | ||
7ea11363 UD |
333 | #ifdef _IO_USE_OLD_IO_FILE |
334 | /* This structure is used by the compatibility code as if it were an | |
335 | _IO_FILE_plus, but has enough space to initialize the _mode argument | |
336 | of an _IO_FILE_complete. */ | |
337 | struct _IO_FILE_complete_plus | |
338 | { | |
339 | struct _IO_FILE_complete file; | |
340 | const struct _IO_jump_t *vtable; | |
341 | }; | |
342 | #endif | |
343 | ||
2ca8b1ee GM |
344 | /* Special file type for fopencookie function. */ |
345 | struct _IO_cookie_file | |
346 | { | |
347 | struct _IO_FILE_plus __fp; | |
348 | void *__cookie; | |
349 | _IO_cookie_io_functions_t __io_functions; | |
350 | }; | |
351 | ||
c9fc9559 RM |
352 | _IO_FILE *_IO_fopencookie (void *cookie, const char *mode, |
353 | _IO_cookie_io_functions_t io_functions); | |
354 | ||
355 | ||
3fc9ca4e UD |
356 | /* Iterator type for walking global linked list of _IO_FILE objects. */ |
357 | ||
73c115ed | 358 | typedef struct _IO_FILE *_IO_ITER; |
3fc9ca4e | 359 | |
96aa2d94 RM |
360 | /* Generic functions */ |
361 | ||
79937577 UD |
362 | extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW; |
363 | extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW; | |
0fca3153 | 364 | extern int _IO_switch_to_get_mode (_IO_FILE *); |
d18ea0c5 | 365 | libc_hidden_proto (_IO_switch_to_get_mode) |
79937577 | 366 | extern void _IO_init (_IO_FILE *, int) __THROW; |
d18ea0c5 | 367 | libc_hidden_proto (_IO_init) |
79937577 | 368 | extern int _IO_sputbackc (_IO_FILE *, int) __THROW; |
d18ea0c5 | 369 | libc_hidden_proto (_IO_sputbackc) |
79937577 UD |
370 | extern int _IO_sungetc (_IO_FILE *) __THROW; |
371 | extern void _IO_un_link (struct _IO_FILE_plus *) __THROW; | |
d18ea0c5 | 372 | libc_hidden_proto (_IO_un_link) |
79937577 | 373 | extern void _IO_link_in (struct _IO_FILE_plus *) __THROW; |
d18ea0c5 | 374 | libc_hidden_proto (_IO_link_in) |
79937577 | 375 | extern void _IO_doallocbuf (_IO_FILE *) __THROW; |
d18ea0c5 | 376 | libc_hidden_proto (_IO_doallocbuf) |
79937577 | 377 | extern void _IO_unsave_markers (_IO_FILE *) __THROW; |
d18ea0c5 | 378 | libc_hidden_proto (_IO_unsave_markers) |
79937577 | 379 | extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW; |
d18ea0c5 | 380 | libc_hidden_proto (_IO_setb) |
79937577 | 381 | extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW; |
d18ea0c5 | 382 | libc_hidden_proto (_IO_adjust_column) |
40a55d20 | 383 | #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n) |
96aa2d94 | 384 | |
d18ea0c5 AS |
385 | _IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW; |
386 | libc_hidden_proto (_IO_least_wmarker) | |
79937577 | 387 | extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW; |
d18ea0c5 | 388 | libc_hidden_proto (_IO_switch_to_main_wget_area) |
79937577 | 389 | extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW; |
d18ea0c5 | 390 | libc_hidden_proto (_IO_switch_to_wbackup_area) |
0fca3153 | 391 | extern int _IO_switch_to_wget_mode (_IO_FILE *); |
d18ea0c5 | 392 | libc_hidden_proto (_IO_switch_to_wget_mode) |
79937577 | 393 | extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW; |
d18ea0c5 | 394 | libc_hidden_proto (_IO_wsetb) |
79937577 | 395 | extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW; |
d18ea0c5 | 396 | libc_hidden_proto (_IO_sputbackwc) |
79937577 UD |
397 | extern wint_t _IO_sungetwc (_IO_FILE *) __THROW; |
398 | extern void _IO_wdoallocbuf (_IO_FILE *) __THROW; | |
d18ea0c5 | 399 | libc_hidden_proto (_IO_wdoallocbuf) |
79937577 UD |
400 | extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW; |
401 | extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW; | |
000232b9 | 402 | extern _IO_off64_t get_file_offset (_IO_FILE *fp); |
d64b6ad0 | 403 | |
96aa2d94 RM |
404 | /* Marker-related function. */ |
405 | ||
0fca3153 UD |
406 | extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *); |
407 | extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *); | |
79937577 UD |
408 | extern void _IO_remove_marker (struct _IO_marker *) __THROW; |
409 | extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *) | |
410 | __THROW; | |
411 | extern int _IO_marker_delta (struct _IO_marker *) __THROW; | |
412 | extern int _IO_wmarker_delta (struct _IO_marker *) __THROW; | |
413 | extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW; | |
414 | extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW; | |
96aa2d94 | 415 | |
79937577 | 416 | /* Functions for iterating global list and dealing with its lock */ |
3fc9ca4e | 417 | |
79937577 | 418 | extern _IO_ITER _IO_iter_begin (void) __THROW; |
1d2b6e0c | 419 | libc_hidden_proto (_IO_iter_begin) |
79937577 | 420 | extern _IO_ITER _IO_iter_end (void) __THROW; |
1d2b6e0c | 421 | libc_hidden_proto (_IO_iter_end) |
79937577 | 422 | extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW; |
1d2b6e0c | 423 | libc_hidden_proto (_IO_iter_next) |
79937577 | 424 | extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW; |
1d2b6e0c | 425 | libc_hidden_proto (_IO_iter_file) |
79937577 | 426 | extern void _IO_list_lock (void) __THROW; |
245eab02 | 427 | libc_hidden_proto (_IO_list_lock) |
79937577 | 428 | extern void _IO_list_unlock (void) __THROW; |
245eab02 | 429 | libc_hidden_proto (_IO_list_unlock) |
79937577 | 430 | extern void _IO_list_resetlock (void) __THROW; |
245eab02 | 431 | libc_hidden_proto (_IO_list_resetlock) |
3fc9ca4e | 432 | |
96aa2d94 RM |
433 | /* Default jumptable functions. */ |
434 | ||
79937577 | 435 | extern int _IO_default_underflow (_IO_FILE *) __THROW; |
0fca3153 | 436 | extern int _IO_default_uflow (_IO_FILE *); |
d18ea0c5 | 437 | libc_hidden_proto (_IO_default_uflow) |
0fca3153 | 438 | extern wint_t _IO_wdefault_uflow (_IO_FILE *); |
d18ea0c5 | 439 | libc_hidden_proto (_IO_wdefault_uflow) |
79937577 | 440 | extern int _IO_default_doallocate (_IO_FILE *) __THROW; |
d18ea0c5 | 441 | libc_hidden_proto (_IO_default_doallocate) |
79937577 | 442 | extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW; |
d18ea0c5 | 443 | libc_hidden_proto (_IO_wdefault_doallocate) |
79937577 | 444 | extern void _IO_default_finish (_IO_FILE *, int) __THROW; |
d18ea0c5 | 445 | libc_hidden_proto (_IO_default_finish) |
79937577 | 446 | extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW; |
d18ea0c5 | 447 | libc_hidden_proto (_IO_wdefault_finish) |
79937577 | 448 | extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW; |
d18ea0c5 | 449 | libc_hidden_proto (_IO_default_pbackfail) |
79937577 | 450 | extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW; |
d18ea0c5 | 451 | libc_hidden_proto (_IO_wdefault_pbackfail) |
0fca3153 | 452 | extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t); |
102070bc | 453 | extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t); |
d18ea0c5 | 454 | libc_hidden_proto (_IO_default_xsputn) |
102070bc | 455 | extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t); |
d18ea0c5 | 456 | libc_hidden_proto (_IO_wdefault_xsputn) |
102070bc | 457 | extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t); |
d18ea0c5 | 458 | libc_hidden_proto (_IO_default_xsgetn) |
102070bc | 459 | extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t); |
d18ea0c5 | 460 | libc_hidden_proto (_IO_wdefault_xsgetn) |
79937577 UD |
461 | extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int) |
462 | __THROW; | |
0fca3153 | 463 | extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int); |
102070bc UD |
464 | extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t); |
465 | extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t); | |
79937577 UD |
466 | extern int _IO_default_stat (_IO_FILE *, void *) __THROW; |
467 | extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW; | |
468 | extern int _IO_default_sync (_IO_FILE *) __THROW; | |
40a55d20 | 469 | #define _IO_default_close ((_IO_close_t) _IO_default_sync) |
79937577 UD |
470 | extern int _IO_default_showmanyc (_IO_FILE *) __THROW; |
471 | extern void _IO_default_imbue (_IO_FILE *, void *) __THROW; | |
96aa2d94 | 472 | |
b2637a22 | 473 | extern const struct _IO_jump_t _IO_file_jumps; |
15a686af | 474 | libc_hidden_proto (_IO_file_jumps) |
b2637a22 UD |
475 | extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden; |
476 | extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden; | |
477 | extern const struct _IO_jump_t _IO_wfile_jumps; | |
15a686af | 478 | libc_hidden_proto (_IO_wfile_jumps) |
b2637a22 UD |
479 | extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden; |
480 | extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden; | |
481 | extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden; | |
482 | extern const struct _IO_jump_t _IO_streambuf_jumps; | |
483 | extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden; | |
484 | extern const struct _IO_jump_t _IO_str_jumps attribute_hidden; | |
485 | extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden; | |
97d261ad | 486 | extern const struct _IO_codecvt __libio_codecvt attribute_hidden; |
0fca3153 | 487 | extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t); |
d18ea0c5 | 488 | libc_hidden_proto (_IO_do_write) |
0fca3153 UD |
489 | extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t); |
490 | extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t); | |
491 | extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t); | |
d18ea0c5 | 492 | libc_hidden_proto (_IO_wdo_write) |
0fca3153 UD |
493 | extern int _IO_flush_all_lockp (int); |
494 | extern int _IO_flush_all (void); | |
d18ea0c5 | 495 | libc_hidden_proto (_IO_flush_all) |
0fca3153 UD |
496 | extern int _IO_cleanup (void); |
497 | extern void _IO_flush_all_linebuffered (void); | |
d18ea0c5 | 498 | libc_hidden_proto (_IO_flush_all_linebuffered) |
0fca3153 UD |
499 | extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *); |
500 | extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *); | |
501 | extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *); | |
502 | extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *); | |
503 | extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *); | |
504 | extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *); | |
505 | extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *); | |
506 | extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *); | |
79937577 | 507 | extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW; |
d64b6ad0 | 508 | |
96aa2d94 | 509 | |
319d719d UD |
510 | #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T |
511 | # define _IO_do_flush(_f) \ | |
d64b6ad0 | 512 | ((_f)->_mode <= 0 \ |
d18ea0c5 AS |
513 | ? _IO_do_write(_f, (_f)->_IO_write_base, \ |
514 | (_f)->_IO_write_ptr-(_f)->_IO_write_base) \ | |
515 | : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \ | |
516 | ((_f)->_wide_data->_IO_write_ptr \ | |
517 | - (_f)->_wide_data->_IO_write_base))) | |
319d719d UD |
518 | #else |
519 | # define _IO_do_flush(_f) \ | |
d18ea0c5 AS |
520 | _IO_do_write(_f, (_f)->_IO_write_base, \ |
521 | (_f)->_IO_write_ptr-(_f)->_IO_write_base) | |
319d719d | 522 | #endif |
6973fc01 UD |
523 | #define _IO_old_do_flush(_f) \ |
524 | _IO_old_do_write(_f, (_f)->_IO_write_base, \ | |
525 | (_f)->_IO_write_ptr-(_f)->_IO_write_base) | |
96aa2d94 RM |
526 | #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING) |
527 | #define _IO_mask_flags(fp, f, mask) \ | |
528 | ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask))) | |
529 | #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\ | |
530 | (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg)) | |
d64b6ad0 UD |
531 | #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\ |
532 | (fp)->_wide_data->_IO_read_ptr = (g), \ | |
533 | (fp)->_wide_data->_IO_read_end = (eg)) | |
96aa2d94 | 534 | #define _IO_setp(__fp, __p, __ep) \ |
d64b6ad0 UD |
535 | ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \ |
536 | = __p, (__fp)->_IO_write_end = (__ep)) | |
537 | #define _IO_wsetp(__fp, __p, __ep) \ | |
538 | ((__fp)->_wide_data->_IO_write_base \ | |
539 | = (__fp)->_wide_data->_IO_write_ptr = __p, \ | |
540 | (__fp)->_wide_data->_IO_write_end = (__ep)) | |
96aa2d94 | 541 | #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL) |
d64b6ad0 | 542 | #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL) |
96aa2d94 RM |
543 | #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP) |
544 | #define _IO_have_markers(fp) ((fp)->_markers != NULL) | |
f65fd747 | 545 | #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base) |
d64b6ad0 UD |
546 | #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \ |
547 | - (fp)->_wide_data->_IO_buf_base) | |
96aa2d94 RM |
548 | |
549 | /* Jumptable functions for files. */ | |
550 | ||
79937577 | 551 | extern int _IO_file_doallocate (_IO_FILE *) __THROW; |
d18ea0c5 | 552 | libc_hidden_proto (_IO_file_doallocate) |
0fca3153 | 553 | extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); |
d18ea0c5 | 554 | libc_hidden_proto (_IO_file_setbuf) |
0fca3153 | 555 | extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); |
d18ea0c5 | 556 | libc_hidden_proto (_IO_file_seekoff) |
79937577 UD |
557 | extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int) |
558 | __THROW; | |
0fca3153 | 559 | extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t); |
d18ea0c5 | 560 | libc_hidden_proto (_IO_file_xsputn) |
0fca3153 | 561 | extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t); |
d18ea0c5 | 562 | libc_hidden_proto (_IO_file_xsgetn) |
79937577 | 563 | extern int _IO_file_stat (_IO_FILE *, void *) __THROW; |
d18ea0c5 | 564 | libc_hidden_proto (_IO_file_stat) |
79937577 | 565 | extern int _IO_file_close (_IO_FILE *) __THROW; |
d18ea0c5 | 566 | libc_hidden_proto (_IO_file_close) |
79937577 | 567 | extern int _IO_file_close_mmap (_IO_FILE *) __THROW; |
0fca3153 | 568 | extern int _IO_file_underflow (_IO_FILE *); |
d18ea0c5 | 569 | libc_hidden_proto (_IO_file_underflow) |
0fca3153 UD |
570 | extern int _IO_file_underflow_mmap (_IO_FILE *); |
571 | extern int _IO_file_underflow_maybe_mmap (_IO_FILE *); | |
572 | extern int _IO_file_overflow (_IO_FILE *, int); | |
d18ea0c5 | 573 | libc_hidden_proto (_IO_file_overflow) |
110215a9 | 574 | #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1) |
79937577 | 575 | extern void _IO_file_init (struct _IO_FILE_plus *) __THROW; |
d18ea0c5 | 576 | libc_hidden_proto (_IO_file_init) |
0fca3153 | 577 | extern _IO_FILE* _IO_file_attach (_IO_FILE *, int); |
d18ea0c5 | 578 | libc_hidden_proto (_IO_file_attach) |
0fca3153 | 579 | extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int); |
ee2a5ae8 | 580 | libc_hidden_proto (_IO_file_open) |
0fca3153 | 581 | extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int); |
d18ea0c5 | 582 | libc_hidden_proto (_IO_file_fopen) |
0fca3153 UD |
583 | extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t); |
584 | extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t); | |
d18ea0c5 | 585 | libc_hidden_proto (_IO_file_read) |
0fca3153 | 586 | extern int _IO_file_sync (_IO_FILE *); |
d18ea0c5 | 587 | libc_hidden_proto (_IO_file_sync) |
0fca3153 | 588 | extern int _IO_file_close_it (_IO_FILE *); |
d18ea0c5 | 589 | libc_hidden_proto (_IO_file_close_it) |
79937577 | 590 | extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW; |
d18ea0c5 | 591 | libc_hidden_proto (_IO_file_seek) |
0fca3153 | 592 | extern void _IO_file_finish (_IO_FILE *, int); |
d18ea0c5 | 593 | libc_hidden_proto (_IO_file_finish) |
79937577 | 594 | |
0fca3153 UD |
595 | extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int); |
596 | extern int _IO_new_file_close_it (_IO_FILE *); | |
597 | extern void _IO_new_file_finish (_IO_FILE *, int); | |
79937577 | 598 | extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *, |
0fca3153 | 599 | int); |
79937577 UD |
600 | extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *, |
601 | const struct _IO_jump_t *) __THROW; | |
602 | extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW; | |
0fca3153 UD |
603 | extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); |
604 | extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t); | |
605 | extern int _IO_new_file_sync (_IO_FILE *); | |
606 | extern int _IO_new_file_underflow (_IO_FILE *); | |
607 | extern int _IO_new_file_overflow (_IO_FILE *, int); | |
608 | extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); | |
609 | extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t); | |
610 | extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t); | |
611 | ||
612 | extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t); | |
613 | extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int); | |
614 | extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t); | |
615 | extern int _IO_old_file_underflow (_IO_FILE *); | |
616 | extern int _IO_old_file_overflow (_IO_FILE *, int); | |
79937577 | 617 | extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW; |
0fca3153 UD |
618 | extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int); |
619 | extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *); | |
620 | extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t); | |
621 | extern int _IO_old_file_sync (_IO_FILE *); | |
622 | extern int _IO_old_file_close_it (_IO_FILE *); | |
623 | extern void _IO_old_file_finish (_IO_FILE *, int); | |
79937577 UD |
624 | |
625 | extern int _IO_wfile_doallocate (_IO_FILE *) __THROW; | |
0fca3153 | 626 | extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t); |
d18ea0c5 | 627 | libc_hidden_proto (_IO_wfile_xsputn) |
0fca3153 UD |
628 | extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t); |
629 | extern wint_t _IO_wfile_sync (_IO_FILE *); | |
d18ea0c5 | 630 | libc_hidden_proto (_IO_wfile_sync) |
0fca3153 | 631 | extern wint_t _IO_wfile_underflow (_IO_FILE *); |
d18ea0c5 | 632 | libc_hidden_proto (_IO_wfile_underflow) |
0fca3153 | 633 | extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t); |
d18ea0c5 | 634 | libc_hidden_proto (_IO_wfile_overflow) |
0fca3153 | 635 | extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int); |
d18ea0c5 | 636 | libc_hidden_proto (_IO_wfile_seekoff) |
d64b6ad0 | 637 | |
96aa2d94 | 638 | /* Jumptable functions for proc_files. */ |
79937577 UD |
639 | extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *) |
640 | __THROW; | |
641 | extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *) | |
642 | __THROW; | |
0fca3153 | 643 | extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *); |
79937577 UD |
644 | extern int _IO_proc_close (_IO_FILE *) __THROW; |
645 | extern int _IO_new_proc_close (_IO_FILE *) __THROW; | |
0fca3153 | 646 | extern int _IO_old_proc_close (_IO_FILE *); |
96aa2d94 RM |
647 | |
648 | /* Jumptable functions for strfiles. */ | |
79937577 | 649 | extern int _IO_str_underflow (_IO_FILE *) __THROW; |
d18ea0c5 | 650 | libc_hidden_proto (_IO_str_underflow) |
79937577 | 651 | extern int _IO_str_overflow (_IO_FILE *, int) __THROW; |
d18ea0c5 | 652 | libc_hidden_proto (_IO_str_overflow) |
79937577 | 653 | extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW; |
d18ea0c5 | 654 | libc_hidden_proto (_IO_str_pbackfail) |
79937577 | 655 | extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW; |
d18ea0c5 | 656 | libc_hidden_proto (_IO_str_seekoff) |
79937577 | 657 | extern void _IO_str_finish (_IO_FILE *, int) __THROW; |
96aa2d94 RM |
658 | |
659 | /* Other strfile functions */ | |
2ca8b1ee | 660 | struct _IO_strfile_; |
79937577 UD |
661 | extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *) |
662 | __THROW; | |
663 | extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int) | |
664 | __THROW; | |
665 | extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW; | |
96aa2d94 | 666 | |
d64b6ad0 | 667 | /* And the wide character versions. */ |
79937577 UD |
668 | extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *) |
669 | __THROW; | |
670 | extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW; | |
671 | extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW; | |
672 | extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW; | |
673 | extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int) | |
674 | __THROW; | |
675 | extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW; | |
676 | extern void _IO_wstr_finish (_IO_FILE *, int) __THROW; | |
677 | ||
a784e502 | 678 | extern int _IO_vasprintf (char **result_ptr, const char *format, |
79937577 | 679 | _IO_va_list args) __THROW; |
a784e502 | 680 | extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg); |
79937577 | 681 | extern int _IO_vsnprintf (char *string, _IO_size_t maxlen, |
a784e502 | 682 | const char *format, _IO_va_list args) __THROW; |
79937577 UD |
683 | |
684 | ||
102070bc | 685 | extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int); |
d18ea0c5 | 686 | libc_hidden_proto (_IO_getline) |
79937577 | 687 | extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t, |
102070bc | 688 | int, int, int *); |
d18ea0c5 | 689 | libc_hidden_proto (_IO_getline_info) |
0fca3153 | 690 | extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *); |
102070bc | 691 | extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int); |
79937577 | 692 | extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t, |
102070bc | 693 | wint_t, int, wint_t *); |
96aa2d94 | 694 | |
2ca8b1ee | 695 | extern struct _IO_FILE_plus *_IO_list_all; |
d18ea0c5 | 696 | libc_hidden_proto (_IO_list_all) |
79937577 | 697 | extern void (*_IO_cleanup_registration_needed) (void); |
96aa2d94 | 698 | |
79937577 UD |
699 | extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *, |
700 | _IO_size_t, char *) __THROW; | |
52a16e58 | 701 | extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int) |
0fca3153 | 702 | attribute_hidden; |
52a16e58 | 703 | extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int) |
0fca3153 | 704 | attribute_hidden; |
77fe0b9c | 705 | |
96aa2d94 | 706 | #ifndef EOF |
40a55d20 | 707 | # define EOF (-1) |
96aa2d94 RM |
708 | #endif |
709 | #ifndef NULL | |
40a55d20 | 710 | # if defined __GNUG__ && \ |
f8b87ef0 | 711 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) |
40a55d20 UD |
712 | # define NULL (__null) |
713 | # else | |
714 | # if !defined(__cplusplus) | |
715 | # define NULL ((void*)0) | |
716 | # else | |
717 | # define NULL (0) | |
718 | # endif | |
719 | # endif | |
f65fd747 | 720 | #endif |
96aa2d94 | 721 | |
f8b87ef0 UD |
722 | #if _G_HAVE_MMAP |
723 | ||
40a55d20 UD |
724 | # include <unistd.h> |
725 | # include <fcntl.h> | |
726 | # include <sys/mman.h> | |
727 | # include <sys/param.h> | |
f8b87ef0 | 728 | |
40a55d20 UD |
729 | # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) |
730 | # define MAP_ANONYMOUS MAP_ANON | |
731 | # endif | |
f8b87ef0 | 732 | |
40a55d20 UD |
733 | # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE) |
734 | # undef _G_HAVE_MMAP | |
735 | # define _G_HAVE_MMAP 0 | |
736 | # endif | |
f8b87ef0 UD |
737 | |
738 | #endif /* _G_HAVE_MMAP */ | |
739 | ||
740 | #if _G_HAVE_MMAP | |
741 | ||
40a55d20 | 742 | # ifdef _LIBC |
10dc2a90 | 743 | /* When using this code in the GNU libc we must not pollute the name space. */ |
40a55d20 UD |
744 | # define mmap __mmap |
745 | # define munmap __munmap | |
dfd2257a | 746 | # define ftruncate __ftruncate |
40a55d20 | 747 | # endif |
10dc2a90 | 748 | |
40a55d20 | 749 | # define ROUND_TO_PAGE(_S) \ |
f8b87ef0 UD |
750 | (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1)) |
751 | ||
40a55d20 | 752 | # define FREE_BUF(_B, _S) \ |
f8b87ef0 | 753 | munmap ((_B), ROUND_TO_PAGE (_S)) |
40a55d20 | 754 | # define ALLOC_BUF(_B, _S, _R) \ |
f8b87ef0 UD |
755 | do { \ |
756 | (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \ | |
757 | PROT_READ | PROT_WRITE, \ | |
758 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ | |
d64b6ad0 UD |
759 | if ((_B) == (char *) MAP_FAILED) \ |
760 | return (_R); \ | |
761 | } while (0) | |
762 | # define ALLOC_WBUF(_B, _S, _R) \ | |
763 | do { \ | |
764 | (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \ | |
765 | PROT_READ | PROT_WRITE, \ | |
766 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ | |
767 | if ((_B) == (wchar_t *) MAP_FAILED) \ | |
f8b87ef0 UD |
768 | return (_R); \ |
769 | } while (0) | |
770 | ||
771 | #else /* _G_HAVE_MMAP */ | |
772 | ||
40a55d20 | 773 | # define FREE_BUF(_B, _S) \ |
f8b87ef0 | 774 | free(_B) |
40a55d20 | 775 | # define ALLOC_BUF(_B, _S, _R) \ |
f8b87ef0 UD |
776 | do { \ |
777 | (_B) = (char*)malloc(_S); \ | |
778 | if ((_B) == NULL) \ | |
779 | return (_R); \ | |
780 | } while (0) | |
af507979 UD |
781 | # define ALLOC_WBUF(_B, _S, _R) \ |
782 | do { \ | |
783 | (_B) = (wchar_t *)malloc(_S); \ | |
784 | if ((_B) == NULL) \ | |
785 | return (_R); \ | |
786 | } while (0) | |
f8b87ef0 UD |
787 | |
788 | #endif /* _G_HAVE_MMAP */ | |
96aa2d94 RM |
789 | |
790 | #ifndef OS_FSTAT | |
40a55d20 | 791 | # define OS_FSTAT fstat |
96aa2d94 | 792 | #endif |
79937577 | 793 | extern int _IO_vscanf (const char *, _IO_va_list) __THROW; |
96aa2d94 | 794 | |
d64b6ad0 | 795 | /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */ |
96aa2d94 | 796 | #ifndef _IO_pos_BAD |
d64b6ad0 | 797 | # define _IO_pos_BAD ((_IO_off64_t) -1) |
96aa2d94 | 798 | #endif |
d64b6ad0 | 799 | /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */ |
96aa2d94 | 800 | #ifndef _IO_pos_adjust |
d64b6ad0 | 801 | # define _IO_pos_adjust(pos, delta) ((pos) += (delta)) |
96aa2d94 | 802 | #endif |
d64b6ad0 | 803 | /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */ |
96aa2d94 | 804 | #ifndef _IO_pos_0 |
d64b6ad0 | 805 | # define _IO_pos_0 ((_IO_off64_t) 0) |
96aa2d94 RM |
806 | #endif |
807 | ||
4547c1a4 UD |
808 | #ifdef __cplusplus |
809 | } | |
810 | #endif | |
96aa2d94 | 811 | |
499e7464 | 812 | #ifdef _IO_MTSAFE_IO |
96aa2d94 | 813 | /* check following! */ |
1ddf537f | 814 | # ifdef _IO_USE_OLD_IO_FILE |
d64b6ad0 | 815 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ |
96aa2d94 | 816 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ |
319d719d | 817 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ |
73c115ed | 818 | 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock } |
1ddf537f | 819 | # else |
319d719d UD |
820 | # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T |
821 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ | |
1ddf537f | 822 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ |
319d719d | 823 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ |
d64b6ad0 UD |
824 | 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\ |
825 | NULL, WDP, 0 } | |
319d719d UD |
826 | # else |
827 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ | |
828 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ | |
829 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ | |
830 | 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\ | |
831 | 0 } | |
832 | # endif | |
1ddf537f | 833 | # endif |
499e7464 | 834 | #else |
1ddf537f | 835 | # ifdef _IO_USE_OLD_IO_FILE |
b4e3df5d | 836 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ |
499e7464 | 837 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ |
73c115ed GM |
838 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ |
839 | 0, _IO_pos_BAD } | |
1ddf537f | 840 | # else |
319d719d UD |
841 | # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T |
842 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ | |
1ddf537f | 843 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ |
319d719d | 844 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ |
d64b6ad0 UD |
845 | 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \ |
846 | NULL, WDP, 0 } | |
319d719d UD |
847 | # else |
848 | # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \ | |
849 | { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \ | |
850 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \ | |
851 | 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \ | |
852 | 0 } | |
853 | # endif | |
1ddf537f | 854 | # endif |
499e7464 | 855 | #endif |
96aa2d94 | 856 | |
965a54a4 | 857 | #define _IO_va_start(args, last) va_start(args, last) |
96aa2d94 RM |
858 | |
859 | extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf; | |
860 | ||
861 | #if 1 | |
40a55d20 | 862 | # define COERCE_FILE(FILE) /* Nothing */ |
96aa2d94 RM |
863 | #else |
864 | /* This is part of the kludge for binary compatibility with old stdio. */ | |
40a55d20 | 865 | # define COERCE_FILE(FILE) \ |
96aa2d94 RM |
866 | (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \ |
867 | && (FILE) = *(FILE**)&((int*)fp)[1]) | |
868 | #endif | |
869 | ||
870 | #ifdef EINVAL | |
40a55d20 | 871 | # define MAYBE_SET_EINVAL __set_errno (EINVAL) |
96aa2d94 | 872 | #else |
40a55d20 | 873 | # define MAYBE_SET_EINVAL /* nothing */ |
96aa2d94 RM |
874 | #endif |
875 | ||
f65fd747 | 876 | #ifdef IO_DEBUG |
40a55d20 | 877 | # define CHECK_FILE(FILE, RET) \ |
96aa2d94 RM |
878 | if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \ |
879 | else { COERCE_FILE(FILE); \ | |
880 | if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \ | |
68dbb3a6 | 881 | { MAYBE_SET_EINVAL; return RET; }} |
96aa2d94 | 882 | #else |
40a55d20 | 883 | # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE) |
96aa2d94 | 884 | #endif |
eef80cf8 UD |
885 | |
886 | static inline void | |
887 | __attribute__ ((__always_inline__)) | |
888 | _IO_acquire_lock_fct (_IO_FILE **p) | |
889 | { | |
890 | _IO_FILE *fp = *p; | |
891 | if ((fp->_flags & _IO_USER_LOCK) == 0) | |
892 | _IO_funlockfile (fp); | |
893 | } | |
b257c726 UD |
894 | |
895 | static inline void | |
896 | __attribute__ ((__always_inline__)) | |
897 | _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p) | |
898 | { | |
899 | _IO_FILE *fp = *p; | |
874aa523 | 900 | fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD); |
b257c726 UD |
901 | if ((fp->_flags & _IO_USER_LOCK) == 0) |
902 | _IO_funlockfile (fp); | |
903 | } | |
b2e1c562 | 904 | |
4f41c682 | 905 | #if !defined _IO_MTSAFE_IO && IS_IN (libc) |
b2e1c562 RM |
906 | # define _IO_acquire_lock(_fp) \ |
907 | do { \ | |
908 | _IO_FILE *_IO_acquire_lock_file = NULL | |
909 | # define _IO_acquire_lock_clear_flags2(_fp) \ | |
910 | do { \ | |
911 | _IO_FILE *_IO_acquire_lock_file = (_fp) | |
912 | # define _IO_release_lock(_fp) \ | |
913 | if (_IO_acquire_lock_file != NULL) \ | |
914 | _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \ | |
915 | | _IO_FLAGS2_SCANF_STD); \ | |
916 | } while (0) | |
917 | #endif |