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