Update.
[glibc.git] / libio / libioP.h
blob5bfaaeb9fc9c60f10bd77a701f6d9b0c8a3a94cf
1 /* Copyright (C) 1993, 1997-2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA.
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 "iolibio.h"
40 /* Control of exported symbols. Used in glibc. By default we don't
41 do anything. */
42 #ifndef INTUSE
43 # define INTUSE(name) name
44 #endif
45 #ifndef INTDEF
46 # define INTDEF(name)
47 #endif
48 #ifndef INTDEF2
49 # define INTDEF2(name)
50 #endif
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
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 #define _IO_seek_set 0
66 #define _IO_seek_cur 1
67 #define _IO_seek_end 2
69 /* THE JUMPTABLE FUNCTIONS.
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
76 * with the _IO_JUMPS macro. The jump table has a eccentric format,
77 * so as to be compatible with the layout of a C++ virtual function table.
78 * (as implemented by g++). When a pointer to a streambuf object is
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
82 * double duty as the virtual function table for C++ streambuf.
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).
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
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
103 #endif
105 #define _IO_JUMPS(THIS) (THIS)->vtable
106 #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
107 #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
109 #if _IO_JUMPS_OFFSET
110 # define _IO_JUMPS_FUNC(THIS) \
111 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
112 + (THIS)->_vtable_offset))
113 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
114 #else
115 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
116 # define _IO_vtable_offset(THIS) 0
117 #endif
118 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
119 #ifdef _G_USING_THUNKS
120 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
121 # define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
122 # define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
123 # define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
124 # define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
125 # define JUMP_INIT(NAME, VALUE) VALUE
126 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
128 # define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
129 # define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
130 # define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
131 # define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
132 #else
133 /* These macros will change when we re-implement vtables to use "thunks"! */
134 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
135 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
136 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
137 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
138 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
139 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
140 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
142 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
143 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
144 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
145 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
146 #endif
148 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
149 It does not delete (free) it, but does everything else to finalize it.
150 It matches the streambuf::~streambuf virtual destructor. */
151 typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
152 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
153 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
155 /* The 'overflow' hook flushes the buffer.
156 The second argument is a character, or EOF.
157 It matches the streambuf::overflow virtual function. */
158 typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
159 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
160 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
162 /* The 'underflow' hook tries to fills the get buffer.
163 It returns the next character (as an unsigned char) or EOF. The next
164 character remains in the get buffer, and the get position is not changed.
165 It matches the streambuf::underflow virtual function. */
166 typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
167 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
168 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
170 /* The 'uflow' hook returns the next character in the input stream
171 (cast to unsigned char), and increments the read position;
172 EOF is returned on failure.
173 It matches the streambuf::uflow virtual function, which is not in the
174 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
175 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
176 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
178 /* The 'pbackfail' hook handles backing up.
179 It matches the streambuf::pbackfail virtual function. */
180 typedef int (*_IO_pbackfail_t) __PMT ((_IO_FILE *, int));
181 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
182 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
184 /* The 'xsputn' hook writes upto N characters from buffer DATA.
185 Returns the number of character actually written.
186 It matches the streambuf::xsputn virtual function. */
187 typedef _IO_size_t (*_IO_xsputn_t) __PMT ((_IO_FILE *FP, const void *DATA,
188 _IO_size_t N));
189 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
190 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
192 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
193 Returns the number of character actually read.
194 It matches the streambuf::xsgetn virtual function. */
195 typedef _IO_size_t (*_IO_xsgetn_t) __PMT ((_IO_FILE *FP, void *DATA,
196 _IO_size_t N));
197 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
198 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
200 /* The 'seekoff' hook moves the stream position to a new position
201 relative to the start of the file (if DIR==0), the current position
202 (MODE==1), or the end of the file (MODE==2).
203 It matches the streambuf::seekoff virtual function.
204 It is also used for the ANSI fseek function. */
205 typedef _IO_off64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
206 int DIR, int MODE));
207 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
208 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
210 /* The 'seekpos' hook also moves the stream position,
211 but to an absolute position given by a fpos64_t (seekpos).
212 It matches the streambuf::seekpos virtual function.
213 It is also used for the ANSI fgetpos and fsetpos functions. */
214 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
215 typedef _IO_off64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
216 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
217 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
219 /* The 'setbuf' hook gives a buffer to the file.
220 It matches the streambuf::setbuf virtual function. */
221 typedef _IO_FILE* (*_IO_setbuf_t) __PMT ((_IO_FILE *, char *, _IO_ssize_t));
222 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
223 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
225 /* The 'sync' hook attempts to synchronize the internal data structures
226 of the file with the external state.
227 It matches the streambuf::sync virtual function. */
228 typedef int (*_IO_sync_t) __PMT ((_IO_FILE *));
229 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
230 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
232 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
233 It matches the streambuf::doallocate virtual function, which is not
234 in the ANSI/ISO C++ standard, but is part traditional implementations. */
235 typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
236 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
237 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
239 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
240 sysstat) are low-level hooks specific to this implementation.
241 There is no correspondence in the ANSI/ISO C++ standard library.
242 The hooks basically correspond to the Unix system functions
243 (read, write, close, lseek, and stat) except that a _IO_FILE*
244 parameter is used instead of a integer file descriptor; the default
245 implementation used for normal files just calls those functions.
246 The advantage of overriding these functions instead of the higher-level
247 ones (underflow, overflow etc) is that you can leave all the buffering
248 higher-level functions. */
250 /* The 'sysread' hook is used to read data from the external file into
251 an existing buffer. It generalizes the Unix read(2) function.
252 It matches the streambuf::sys_read virtual function, which is
253 specific to this implementation. */
254 typedef _IO_ssize_t (*_IO_read_t) __PMT ((_IO_FILE *, void *, _IO_ssize_t));
255 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
256 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
258 /* The 'syswrite' hook is used to write data from an existing buffer
259 to an external file. It generalizes the Unix write(2) function.
260 It matches the streambuf::sys_write virtual function, which is
261 specific to this implementation. */
262 typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *, const void *,
263 _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) __PMT ((_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) __PMT ((_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) __PMT ((_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) __PMT ((_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) __PMT ((_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 __P ((_IO_FILE *));
381 extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
382 extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
383 extern void _IO_init __P ((_IO_FILE *, int));
384 extern int _IO_sputbackc __P ((_IO_FILE *, int));
385 extern int _IO_sungetc __P ((_IO_FILE *));
386 extern void _IO_un_link __P ((struct _IO_FILE_plus *));
387 extern void _IO_link_in __P ((struct _IO_FILE_plus *));
388 extern void _IO_doallocbuf __P ((_IO_FILE *));
389 extern void _IO_unsave_markers __P ((_IO_FILE *));
390 extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
391 extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
392 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
394 extern void _IO_switch_to_main_wget_area __P ((_IO_FILE *));
395 extern void _IO_switch_to_wbackup_area __P ((_IO_FILE *));
396 extern int _IO_switch_to_wget_mode __P ((_IO_FILE *));
397 extern void _IO_wsetb __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
398 extern wint_t _IO_sputbackwc __P ((_IO_FILE *, wint_t));
399 extern wint_t _IO_sungetwc __P ((_IO_FILE *));
400 extern void _IO_wdoallocbuf __P ((_IO_FILE *));
401 extern void _IO_unsave_wmarkers __P ((_IO_FILE *));
402 extern unsigned _IO_adjust_wcolumn __P ((unsigned, const wchar_t *, int));
404 /* Marker-related function. */
406 extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
407 extern void _IO_init_wmarker __P ((struct _IO_marker *, _IO_FILE *));
408 extern void _IO_remove_marker __P ((struct _IO_marker *));
409 extern int _IO_marker_difference __P ((struct _IO_marker *,
410 struct _IO_marker *));
411 extern int _IO_marker_delta __P ((struct _IO_marker *));
412 extern int _IO_wmarker_delta __P ((struct _IO_marker *));
413 extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
414 extern int _IO_seekwmark __P ((_IO_FILE *, struct _IO_marker *, int));
416 /* Functions for iterating global list and dealing with
417 its lock */
419 extern _IO_ITER _IO_iter_begin __P ((void));
420 libc_hidden_proto (_IO_iter_begin)
421 extern _IO_ITER _IO_iter_end __P ((void));
422 libc_hidden_proto (_IO_iter_end)
423 extern _IO_ITER _IO_iter_next __P ((_IO_ITER));
424 libc_hidden_proto (_IO_iter_next)
425 extern _IO_FILE *_IO_iter_file __P ((_IO_ITER));
426 libc_hidden_proto (_IO_iter_file)
427 extern void _IO_list_lock __P ((void));
428 libc_hidden_proto (_IO_list_lock)
429 extern void _IO_list_unlock __P ((void));
430 libc_hidden_proto (_IO_list_unlock)
431 extern void _IO_list_resetlock __P ((void));
432 libc_hidden_proto (_IO_list_resetlock)
434 /* Default jumptable functions. */
436 extern int _IO_default_underflow __P ((_IO_FILE *));
437 extern int _IO_default_uflow __P ((_IO_FILE *));
438 extern wint_t _IO_wdefault_uflow __P ((_IO_FILE *));
439 extern int _IO_default_doallocate __P ((_IO_FILE *));
440 extern int _IO_wdefault_doallocate __P ((_IO_FILE *));
441 extern void _IO_default_finish __P ((_IO_FILE *, int));
442 extern void _IO_wdefault_finish __P ((_IO_FILE *, int));
443 extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
444 extern wint_t _IO_wdefault_pbackfail __P ((_IO_FILE *, wint_t));
445 extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
446 extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
447 _IO_size_t));
448 extern _IO_size_t _IO_wdefault_xsputn __P ((_IO_FILE *, const void *,
449 _IO_size_t));
450 extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
451 extern _IO_size_t _IO_wdefault_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
452 extern _IO_off64_t _IO_default_seekoff __P ((_IO_FILE *,
453 _IO_off64_t, int, int));
454 extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
455 extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
456 _IO_ssize_t));
457 extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
458 extern int _IO_default_stat __P ((_IO_FILE *, void *));
459 extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
460 extern int _IO_default_sync __P ((_IO_FILE *));
461 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
462 extern int _IO_default_showmanyc __P ((_IO_FILE *));
463 extern void _IO_default_imbue __P ((_IO_FILE *, void *));
465 extern const struct _IO_jump_t _IO_file_jumps;
466 libc_hidden_proto (_IO_file_jumps)
467 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
468 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
469 extern const struct _IO_jump_t _IO_wfile_jumps;
470 libc_hidden_proto (_IO_wfile_jumps)
471 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
472 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
473 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
474 extern const struct _IO_jump_t _IO_streambuf_jumps;
475 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
476 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
477 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
478 extern struct _IO_codecvt __libio_codecvt attribute_hidden;
479 extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
480 extern int _IO_new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
481 extern int _IO_old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
482 extern int _IO_wdo_write __P ((_IO_FILE *, const wchar_t *, _IO_size_t));
483 extern int _IO_flush_all_lockp __P ((int));
484 extern int _IO_flush_all __P ((void));
485 extern int _IO_cleanup __P ((void));
486 extern void _IO_flush_all_linebuffered __P ((void));
487 extern int _IO_new_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
488 extern int _IO_old_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
489 extern int _IO_new_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
490 extern int _IO_old_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
491 extern int _IO_new_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
492 extern int _IO_old_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
493 extern int _IO_new_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
494 extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
495 extern void _IO_old_init __P ((_IO_FILE *fp, int flags));
498 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
499 # define _IO_do_flush(_f) \
500 ((_f)->_mode <= 0 \
501 ? INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
502 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
503 : INTUSE(_IO_wdo_write)(_f, (_f)->_wide_data->_IO_write_base, \
504 ((_f)->_wide_data->_IO_write_ptr \
505 - (_f)->_wide_data->_IO_write_base)))
506 #else
507 # define _IO_do_flush(_f) \
508 INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
509 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
510 #endif
511 #define _IO_old_do_flush(_f) \
512 _IO_old_do_write(_f, (_f)->_IO_write_base, \
513 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
514 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
515 #define _IO_mask_flags(fp, f, mask) \
516 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
517 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
518 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
519 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
520 (fp)->_wide_data->_IO_read_ptr = (g), \
521 (fp)->_wide_data->_IO_read_end = (eg))
522 #define _IO_setp(__fp, __p, __ep) \
523 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
524 = __p, (__fp)->_IO_write_end = (__ep))
525 #define _IO_wsetp(__fp, __p, __ep) \
526 ((__fp)->_wide_data->_IO_write_base \
527 = (__fp)->_wide_data->_IO_write_ptr = __p, \
528 (__fp)->_wide_data->_IO_write_end = (__ep))
529 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
530 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
531 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
532 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
533 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
534 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
535 - (fp)->_wide_data->_IO_buf_base)
537 /* Jumptable functions for files. */
539 extern int _IO_file_doallocate __P ((_IO_FILE *));
540 extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
541 extern _IO_off64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
542 extern _IO_off64_t _IO_file_seekoff_mmap __P ((_IO_FILE *, _IO_off64_t, int,
543 int));
544 extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
545 extern _IO_size_t _IO_file_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
546 extern int _IO_file_stat __P ((_IO_FILE *, void *));
547 extern int _IO_file_close __P ((_IO_FILE *));
548 extern int _IO_file_close_mmap __P ((_IO_FILE *));
549 extern int _IO_file_underflow __P ((_IO_FILE *));
550 extern int _IO_file_underflow_mmap __P ((_IO_FILE *));
551 extern int _IO_file_underflow_maybe_mmap __P ((_IO_FILE *));
552 extern int _IO_file_overflow __P ((_IO_FILE *, int));
553 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
554 extern void _IO_file_init __P ((struct _IO_FILE_plus *));
555 extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
556 extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
557 int, int));
558 libc_hidden_proto (_IO_file_open)
559 extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
560 int));
561 extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
562 _IO_ssize_t));
563 extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
564 extern int _IO_file_sync __P ((_IO_FILE *));
565 extern int _IO_file_close_it __P ((_IO_FILE *));
566 extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
567 extern void _IO_file_finish __P ((_IO_FILE *, int));
569 extern _IO_FILE* _IO_new_file_attach __P ((_IO_FILE *, int));
570 extern int _IO_new_file_close_it __P ((_IO_FILE *));
571 extern void _IO_new_file_finish __P ((_IO_FILE *, int));
572 extern _IO_FILE* _IO_new_file_fopen __P ((_IO_FILE *, const char *, const char *,
573 int));
574 extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
575 const struct _IO_jump_t *));
576 extern void _IO_new_file_init __P ((struct _IO_FILE_plus *));
577 extern _IO_FILE* _IO_new_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
578 extern _IO_FILE* _IO_file_setbuf_mmap __P ((_IO_FILE *, char *, _IO_ssize_t));
579 extern int _IO_new_file_sync __P ((_IO_FILE *));
580 extern int _IO_new_file_underflow __P ((_IO_FILE *));
581 extern int _IO_new_file_overflow __P ((_IO_FILE *, int));
582 extern _IO_off64_t _IO_new_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
583 extern _IO_ssize_t _IO_new_file_write __P ((_IO_FILE *, const void *,
584 _IO_ssize_t));
585 extern _IO_size_t _IO_new_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
587 extern _IO_FILE* _IO_old_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
588 extern _IO_off64_t _IO_old_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int,
589 int));
590 extern _IO_size_t _IO_old_file_xsputn __P ((_IO_FILE *, const void *,
591 _IO_size_t));
592 extern int _IO_old_file_underflow __P ((_IO_FILE *));
593 extern int _IO_old_file_overflow __P ((_IO_FILE *, int));
594 extern void _IO_old_file_init __P ((struct _IO_FILE_plus *));
595 extern _IO_FILE* _IO_old_file_attach __P ((_IO_FILE *, int));
596 extern _IO_FILE* _IO_old_file_fopen __P ((_IO_FILE *, const char *,
597 const char *));
598 extern _IO_ssize_t _IO_old_file_write __P ((_IO_FILE *, const void *,
599 _IO_ssize_t));
600 extern int _IO_old_file_sync __P ((_IO_FILE *));
601 extern int _IO_old_file_close_it __P ((_IO_FILE *));
602 extern void _IO_old_file_finish __P ((_IO_FILE *, int));
604 extern int _IO_wfile_doallocate __P ((_IO_FILE *));
605 extern _IO_size_t _IO_wfile_xsputn __P ((_IO_FILE *, const void *,
606 _IO_size_t));
607 extern _IO_FILE* _IO_wfile_setbuf __P ((_IO_FILE *, wchar_t *, _IO_ssize_t));
608 extern wint_t _IO_wfile_sync __P ((_IO_FILE *));
609 extern wint_t _IO_wfile_underflow __P ((_IO_FILE *));
610 extern wint_t _IO_wfile_overflow __P ((_IO_FILE *, wint_t));
611 extern _IO_off64_t _IO_wfile_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
613 /* Jumptable functions for proc_files. */
614 extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
615 extern _IO_FILE* _IO_new_proc_open __P ((_IO_FILE *, const char *, const char *));
616 extern _IO_FILE* _IO_old_proc_open __P ((_IO_FILE *, const char *, const char *));
617 extern int _IO_proc_close __P ((_IO_FILE *));
618 extern int _IO_new_proc_close __P ((_IO_FILE *));
619 extern int _IO_old_proc_close __P ((_IO_FILE *));
621 /* Jumptable functions for strfiles. */
622 extern int _IO_str_underflow __P ((_IO_FILE *));
623 extern int _IO_str_overflow __P ((_IO_FILE *, int));
624 extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
625 extern _IO_off64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
626 extern void _IO_str_finish __P ((_IO_FILE *, int));
628 /* Other strfile functions */
629 struct _IO_strfile_;
630 extern void _IO_str_init_static __P ((struct _IO_strfile_ *, char *, int, char *));
631 extern void _IO_str_init_readonly __P ((struct _IO_strfile_ *, const char *, int));
632 extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
634 /* And the wide character versions. */
635 extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *));
636 extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
637 extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
638 extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
639 extern _IO_off64_t _IO_wstr_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
640 extern _IO_wint_t _IO_wstr_pbackfail __P ((_IO_FILE *, _IO_wint_t));
641 extern void _IO_wstr_finish __P ((_IO_FILE *, int));
643 extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
644 _IO_va_list args));
645 extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
646 extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
647 __const char *format, _IO_va_list args));
650 extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
651 extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
652 int, int, int *));
653 extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
654 extern _IO_size_t _IO_getwline __P ((_IO_FILE *,wchar_t *, _IO_size_t, wint_t,
655 int));
656 extern _IO_size_t _IO_getwline_info __P ((_IO_FILE *,wchar_t *, _IO_size_t,
657 wint_t, int, wint_t *));
658 extern double _IO_strtod __P ((const char *, char **));
659 extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
660 int *__decpt, int *__sign, char **__rve));
661 extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
662 int __width, int __precision, int __flags,
663 int __sign_mode, int __fill));
665 extern struct _IO_FILE_plus *_IO_list_all;
666 extern void (*_IO_cleanup_registration_needed) __PMT ((void));
668 /* Prototype for functions with alternative entry point. */
669 extern int _IO_flush_all_internal __P ((void));
670 extern unsigned _IO_adjust_column_internal __P ((unsigned, const char *, int));
672 extern int _IO_default_uflow_internal __P ((_IO_FILE *));
673 extern void _IO_default_finish_internal __P ((_IO_FILE *, int));
674 extern int _IO_default_pbackfail_internal __P ((_IO_FILE *, int));
675 extern _IO_size_t _IO_default_xsputn_internal __P ((_IO_FILE *, const void *,
676 _IO_size_t));
677 extern _IO_size_t _IO_default_xsgetn_internal __P ((_IO_FILE *, void *,
678 _IO_size_t));
679 extern int _IO_default_doallocate_internal __P ((_IO_FILE *));
680 extern void _IO_wdefault_finish_internal __P ((_IO_FILE *, int));
681 extern wint_t _IO_wdefault_pbackfail_internal __P ((_IO_FILE *, wint_t));
682 extern _IO_size_t _IO_wdefault_xsputn_internal __P ((_IO_FILE *, const void *,
683 _IO_size_t));
684 extern _IO_size_t _IO_wdefault_xsgetn_internal __P ((_IO_FILE *, void *,
685 _IO_size_t));
686 extern int _IO_wdefault_doallocate_internal __P ((_IO_FILE *));
687 extern wint_t _IO_wdefault_uflow_internal __P ((_IO_FILE *));
689 extern int _IO_file_doallocate_internal __P ((_IO_FILE *));
690 extern _IO_FILE* _IO_file_setbuf_internal __P ((_IO_FILE *, char *,
691 _IO_ssize_t));
692 extern _IO_off64_t _IO_file_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
693 int, int));
694 extern _IO_size_t _IO_file_xsputn_internal __P ((_IO_FILE *, const void *,
695 _IO_size_t));
696 extern _IO_size_t _IO_file_xsgetn_internal __P ((_IO_FILE *, void *,
697 _IO_size_t));
698 extern int _IO_file_stat_internal __P ((_IO_FILE *, void *));
699 extern int _IO_file_close_internal __P ((_IO_FILE *));
700 extern int _IO_file_close_it_internal __P ((_IO_FILE *));
701 extern int _IO_file_underflow_internal __P ((_IO_FILE *));
702 extern int _IO_file_overflow_internal __P ((_IO_FILE *, int));
703 extern void _IO_file_init_internal __P ((struct _IO_FILE_plus *));
704 extern _IO_FILE* _IO_file_attach_internal __P ((_IO_FILE *, int));
705 extern _IO_FILE* _IO_file_fopen_internal __P ((_IO_FILE *, const char *,
706 const char *, int));
707 extern _IO_ssize_t _IO_file_read_internal __P ((_IO_FILE *, void *,
708 _IO_ssize_t));
709 extern int _IO_file_sync_internal __P ((_IO_FILE *));
710 extern _IO_off64_t _IO_file_seek_internal __P ((_IO_FILE *, _IO_off64_t, int));
711 extern void _IO_file_finish_internal __P ((_IO_FILE *, int));
713 extern _IO_size_t _IO_wfile_xsputn_internal __P ((_IO_FILE *, const void *,
714 _IO_size_t));
715 extern _IO_off64_t _IO_wfile_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
716 int, int));
717 extern wint_t _IO_wfile_sync_internal __P ((_IO_FILE *));
719 extern int _IO_str_underflow_internal __P ((_IO_FILE *));
720 extern int _IO_str_overflow_internal __P ((_IO_FILE *, int));
721 extern int _IO_str_pbackfail_internal __P ((_IO_FILE *, int));
722 extern _IO_off64_t _IO_str_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
723 int, int));
724 extern void _IO_str_init_static_internal __P ((struct _IO_strfile_ *, char *,
725 _IO_size_t, char *));
727 extern struct _IO_jump_t _IO_file_jumps_internal attribute_hidden;
728 extern struct _IO_jump_t _IO_wfile_jumps_internal attribute_hidden;
730 extern struct _IO_FILE_plus *_IO_list_all_internal attribute_hidden;
732 extern void _IO_link_in_internal __P ((struct _IO_FILE_plus *));
733 extern int _IO_sputbackc_internal __P ((_IO_FILE *, int));
734 extern void _IO_wdoallocbuf_internal __P ((_IO_FILE *));
736 extern _IO_size_t _IO_sgetn_internal (_IO_FILE *, void *, _IO_size_t);
737 extern void _IO_flush_all_linebuffered_internal __P ((void));
738 extern int _IO_switch_to_wget_mode_internal __P ((_IO_FILE *));
739 extern void _IO_unsave_markers_internal __P ((_IO_FILE *));
740 extern void _IO_switch_to_main_wget_area_internal __P ((_IO_FILE *));
741 extern int _IO_wdo_write_internal __P ((_IO_FILE *, const wchar_t *,
742 _IO_size_t));
743 extern int _IO_do_write_internal __P ((_IO_FILE *, const char *, _IO_size_t));
744 extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t);
745 extern _IO_size_t _IO_getline_info_internal __P ((_IO_FILE *,char *,
746 _IO_size_t, int, int,
747 int *));
748 extern _IO_size_t _IO_getline_internal __P ((_IO_FILE *, char *, _IO_size_t,
749 int, int));
750 extern void _IO_free_wbackup_area_internal (_IO_FILE *);
751 extern void _IO_free_backup_area_internal (_IO_FILE *);
752 extern void _IO_switch_to_wbackup_area_internal __P ((_IO_FILE *));
753 extern void _IO_setb_internal __P ((_IO_FILE *, char *, char *, int));
754 extern wint_t _IO_sputbackwc_internal __P ((_IO_FILE *, wint_t));
755 extern int _IO_switch_to_get_mode_internal __P ((_IO_FILE *));
756 extern int _IO_vfscanf_internal (_IO_FILE * __restrict,
757 const char * __restrict,
758 _IO_va_list, int *__restrict);
759 extern int _IO_vfprintf_internal (_IO_FILE *__restrict, const char *__restrict,
760 _IO_va_list);
761 extern void _IO_doallocbuf_internal __P ((_IO_FILE *));
762 extern void _IO_wsetb_internal __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
763 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
764 attribute_hidden;
765 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
766 attribute_hidden;
767 extern int _IO_putc_internal (int __c, _IO_FILE *__fp);
768 extern void _IO_init_internal __P ((_IO_FILE *, int));
769 extern void _IO_un_link_internal __P ((struct _IO_FILE_plus *));
771 #ifndef EOF
772 # define EOF (-1)
773 #endif
774 #ifndef NULL
775 # if defined __GNUG__ && \
776 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
777 # define NULL (__null)
778 # else
779 # if !defined(__cplusplus)
780 # define NULL ((void*)0)
781 # else
782 # define NULL (0)
783 # endif
784 # endif
785 #endif
787 #if _G_HAVE_MMAP
789 # include <unistd.h>
790 # include <fcntl.h>
791 # include <sys/mman.h>
792 # include <sys/param.h>
794 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
795 # define MAP_ANONYMOUS MAP_ANON
796 # endif
798 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
799 # undef _G_HAVE_MMAP
800 # define _G_HAVE_MMAP 0
801 # endif
803 #endif /* _G_HAVE_MMAP */
805 #if _G_HAVE_MMAP
807 # ifdef _LIBC
808 /* When using this code in the GNU libc we must not pollute the name space. */
809 # define mmap __mmap
810 # define munmap __munmap
811 # define ftruncate __ftruncate
812 # endif
814 # define ROUND_TO_PAGE(_S) \
815 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
817 # define FREE_BUF(_B, _S) \
818 munmap ((_B), ROUND_TO_PAGE (_S))
819 # define ALLOC_BUF(_B, _S, _R) \
820 do { \
821 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
822 PROT_READ | PROT_WRITE, \
823 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
824 if ((_B) == (char *) MAP_FAILED) \
825 return (_R); \
826 } while (0)
827 # define ALLOC_WBUF(_B, _S, _R) \
828 do { \
829 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
830 PROT_READ | PROT_WRITE, \
831 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
832 if ((_B) == (wchar_t *) MAP_FAILED) \
833 return (_R); \
834 } while (0)
836 #else /* _G_HAVE_MMAP */
838 # define FREE_BUF(_B, _S) \
839 free(_B)
840 # define ALLOC_BUF(_B, _S, _R) \
841 do { \
842 (_B) = (char*)malloc(_S); \
843 if ((_B) == NULL) \
844 return (_R); \
845 } while (0)
846 # define ALLOC_WBUF(_B, _S, _R) \
847 do { \
848 (_B) = (wchar_t *)malloc(_S); \
849 if ((_B) == NULL) \
850 return (_R); \
851 } while (0)
853 #endif /* _G_HAVE_MMAP */
855 #ifndef OS_FSTAT
856 # define OS_FSTAT fstat
857 #endif
858 struct stat;
859 extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
860 extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
861 extern _IO_off64_t _IO_lseek __P ((int, _IO_off64_t, int));
862 extern int _IO_close __P ((int));
863 extern int _IO_fstat __P ((int, struct stat *));
864 extern int _IO_vscanf __P ((const char *, _IO_va_list));
866 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
867 #ifndef _IO_pos_BAD
868 # define _IO_pos_BAD ((_IO_off64_t) -1)
869 #endif
870 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
871 #ifndef _IO_pos_adjust
872 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
873 #endif
874 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
875 #ifndef _IO_pos_0
876 # define _IO_pos_0 ((_IO_off64_t) 0)
877 #endif
879 #ifdef __cplusplus
881 #endif
883 #ifdef _IO_MTSAFE_IO
884 /* check following! */
885 # ifdef _IO_USE_OLD_IO_FILE
886 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
887 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
888 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
889 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
890 # else
891 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
892 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
893 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
894 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
895 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
896 NULL, WDP, 0 }
897 # else
898 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
899 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
900 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
901 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
903 # endif
904 # endif
905 #else
906 # ifdef _IO_USE_OLD_IO_FILE
907 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
908 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
909 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
910 0, _IO_pos_BAD }
911 # else
912 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
913 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
914 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
915 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
916 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
917 NULL, WDP, 0 }
918 # else
919 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
920 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
921 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
922 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
924 # endif
925 # endif
926 #endif
928 /* VTABLE_LABEL defines NAME as of the CLASS class.
929 CNLENGTH is strlen(#CLASS). */
930 #ifdef __GNUC__
931 # if _G_VTABLE_LABEL_HAS_LENGTH
932 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
933 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
934 # else
935 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
936 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
937 # endif
938 #endif /* __GNUC__ */
940 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
941 # ifdef __GNUC__
942 VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
943 # else
944 # if _G_VTABLE_LABEL_HAS_LENGTH
945 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
946 # else
947 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
948 # endif
949 # endif
950 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
952 #if defined(__STDC__) || defined(__cplusplus)
953 # define _IO_va_start(args, last) va_start(args, last)
954 #else
955 # define _IO_va_start(args, last) va_start(args)
956 #endif
958 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
960 #if 1
961 # define COERCE_FILE(FILE) /* Nothing */
962 #else
963 /* This is part of the kludge for binary compatibility with old stdio. */
964 # define COERCE_FILE(FILE) \
965 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
966 && (FILE) = *(FILE**)&((int*)fp)[1])
967 #endif
969 #ifdef EINVAL
970 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
971 #else
972 # define MAYBE_SET_EINVAL /* nothing */
973 #endif
975 #ifdef IO_DEBUG
976 # define CHECK_FILE(FILE, RET) \
977 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
978 else { COERCE_FILE(FILE); \
979 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
980 { MAYBE_SET_EINVAL; return RET; }}
981 #else
982 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
983 #endif
985 static inline void
986 __attribute__ ((__always_inline__))
987 _IO_acquire_lock_fct (_IO_FILE **p)
989 _IO_FILE *fp = *p;
990 if ((fp->_flags & _IO_USER_LOCK) == 0)
991 _IO_funlockfile (fp);