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