libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / libroot / posix / glibc / libio / libioP.h
blobcb1a48ac29a4345213ffa753bfb012d470f4b619
1 /* Copyright (C) 1993, 1997-2002, 2003 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 #ifndef _LIBIO_P_H_
29 #define _LIBIO_P_H_
31 #include <errno.h>
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 #else
114 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
115 #endif
116 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
117 #ifdef _G_USING_THUNKS
118 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
119 # define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
120 # define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
121 # define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
122 # define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
123 # define JUMP_INIT(NAME, VALUE) VALUE
124 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
126 # define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
127 # define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
128 # define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
129 # define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
130 #else
131 /* These macros will change when we re-implement vtables to use "thunks"! */
132 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
133 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
134 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
135 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
136 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
137 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
138 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
140 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
141 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
142 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
143 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
144 #endif
146 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
147 It does not delete (free) it, but does everything else to finalize it.
148 It matches the streambuf::~streambuf virtual destructor. */
149 typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
150 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
151 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
153 /* The 'overflow' hook flushes the buffer.
154 The second argument is a character, or EOF.
155 It matches the streambuf::overflow virtual function. */
156 typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
157 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
158 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
160 /* The 'underflow' hook tries to fills the get buffer.
161 It returns the next character (as an unsigned char) or EOF. The next
162 character remains in the get buffer, and the get position is not changed.
163 It matches the streambuf::underflow virtual function. */
164 typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
165 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
166 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
168 /* The 'uflow' hook returns the next character in the input stream
169 (cast to unsigned char), and increments the read position;
170 EOF is returned on failure.
171 It matches the streambuf::uflow virtual function, which is not in the
172 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
173 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
174 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
176 /* The 'pbackfail' hook handles backing up.
177 It matches the streambuf::pbackfail virtual function. */
178 typedef int (*_IO_pbackfail_t) __PMT ((_IO_FILE *, int));
179 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
180 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
182 /* The 'xsputn' hook writes upto N characters from buffer DATA.
183 Returns the number of character actually written.
184 It matches the streambuf::xsputn virtual function. */
185 typedef _IO_size_t (*_IO_xsputn_t) __PMT ((_IO_FILE *FP, const void *DATA,
186 _IO_size_t N));
187 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
188 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
190 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
191 Returns the number of character actually read.
192 It matches the streambuf::xsgetn virtual function. */
193 typedef _IO_size_t (*_IO_xsgetn_t) __PMT ((_IO_FILE *FP, void *DATA,
194 _IO_size_t N));
195 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
196 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
198 /* The 'seekoff' hook moves the stream position to a new position
199 relative to the start of the file (if DIR==0), the current position
200 (MODE==1), or the end of the file (MODE==2).
201 It matches the streambuf::seekoff virtual function.
202 It is also used for the ANSI fseek function. */
203 typedef _IO_off64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
204 int DIR, int MODE));
205 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
206 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
208 /* The 'seekpos' hook also moves the stream position,
209 but to an absolute position given by a fpos64_t (seekpos).
210 It matches the streambuf::seekpos virtual function.
211 It is also used for the ANSI fgetpos and fsetpos functions. */
212 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
213 typedef _IO_off64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
214 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
215 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
217 /* The 'setbuf' hook gives a buffer to the file.
218 It matches the streambuf::setbuf virtual function. */
219 typedef _IO_FILE* (*_IO_setbuf_t) __PMT ((_IO_FILE *, char *, _IO_ssize_t));
220 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
221 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
223 /* The 'sync' hook attempts to synchronize the internal data structures
224 of the file with the external state.
225 It matches the streambuf::sync virtual function. */
226 typedef int (*_IO_sync_t) __PMT ((_IO_FILE *));
227 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
228 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
230 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
231 It matches the streambuf::doallocate virtual function, which is not
232 in the ANSI/ISO C++ standard, but is part traditional implementations. */
233 typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
234 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
235 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
237 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
238 sysstat) are low-level hooks specific to this implementation.
239 There is no correspondence in the ANSI/ISO C++ standard library.
240 The hooks basically correspond to the Unix system functions
241 (read, write, close, lseek, and stat) except that a _IO_FILE*
242 parameter is used instead of a integer file descriptor; the default
243 implementation used for normal files just calls those functions.
244 The advantage of overriding these functions instead of the higher-level
245 ones (underflow, overflow etc) is that you can leave all the buffering
246 higher-level functions. */
248 /* The 'sysread' hook is used to read data from the external file into
249 an existing buffer. It generalizes the Unix read(2) function.
250 It matches the streambuf::sys_read virtual function, which is
251 specific to this implementation. */
252 typedef _IO_ssize_t (*_IO_read_t) __PMT ((_IO_FILE *, void *, _IO_ssize_t));
253 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
254 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
256 /* The 'syswrite' hook is used to write data from an existing buffer
257 to an external file. It generalizes the Unix write(2) function.
258 It matches the streambuf::sys_write virtual function, which is
259 specific to this implementation. */
260 typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *, const void *,
261 _IO_ssize_t));
262 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
263 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
265 /* The 'sysseek' hook is used to re-position an external file.
266 It generalizes the Unix lseek(2) function.
267 It matches the streambuf::sys_seek virtual function, which is
268 specific to this implementation. */
269 typedef _IO_off64_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
270 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
271 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
273 /* The 'sysclose' hook is used to finalize (close, finish up) an
274 external file. It generalizes the Unix close(2) function.
275 It matches the streambuf::sys_close virtual function, which is
276 specific to this implementation. */
277 typedef int (*_IO_close_t) __PMT ((_IO_FILE *)); /* finalize */
278 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
279 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
281 /* The 'sysstat' hook is used to get information about an external file
282 into a struct stat buffer. It generalizes the Unix fstat(2) call.
283 It matches the streambuf::sys_stat virtual function, which is
284 specific to this implementation. */
285 typedef int (*_IO_stat_t) __PMT ((_IO_FILE *, void *));
286 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
287 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
289 /* The 'showmany' hook can be used to get an image how much input is
290 available. In many cases the answer will be 0 which means unknown
291 but some cases one can provide real information. */
292 typedef int (*_IO_showmanyc_t) __PMT ((_IO_FILE *));
293 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
294 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
296 /* The 'imbue' hook is used to get information about the currently
297 installed locales. */
298 typedef void (*_IO_imbue_t) __PMT ((_IO_FILE *, void *));
299 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
300 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
303 #define _IO_CHAR_TYPE char /* unsigned char ? */
304 #define _IO_INT_TYPE int
306 struct _IO_jump_t
308 JUMP_FIELD(_G_size_t, __dummy);
309 #ifdef _G_USING_THUNKS
310 JUMP_FIELD(_G_size_t, __dummy2);
311 #endif
312 JUMP_FIELD(_IO_finish_t, __finish);
313 JUMP_FIELD(_IO_overflow_t, __overflow);
314 JUMP_FIELD(_IO_underflow_t, __underflow);
315 JUMP_FIELD(_IO_underflow_t, __uflow);
316 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
317 /* showmany */
318 JUMP_FIELD(_IO_xsputn_t, __xsputn);
319 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
320 JUMP_FIELD(_IO_seekoff_t, __seekoff);
321 JUMP_FIELD(_IO_seekpos_t, __seekpos);
322 JUMP_FIELD(_IO_setbuf_t, __setbuf);
323 JUMP_FIELD(_IO_sync_t, __sync);
324 JUMP_FIELD(_IO_doallocate_t, __doallocate);
325 JUMP_FIELD(_IO_read_t, __read);
326 JUMP_FIELD(_IO_write_t, __write);
327 JUMP_FIELD(_IO_seek_t, __seek);
328 JUMP_FIELD(_IO_close_t, __close);
329 JUMP_FIELD(_IO_stat_t, __stat);
330 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
331 JUMP_FIELD(_IO_imbue_t, __imbue);
332 #if 0
333 get_column;
334 set_column;
335 #endif
338 /* We always allocate an extra word following an _IO_FILE.
339 This contains a pointer to the function jump table used.
340 This is for compatibility with C++ streambuf; the word can
341 be used to smash to a pointer to a virtual function table. */
343 struct _IO_FILE_plus
345 _IO_FILE file;
346 const struct _IO_jump_t *vtable;
349 /* Special file type for fopencookie function. */
350 struct _IO_cookie_file
352 struct _IO_FILE_plus __fp;
353 void *__cookie;
354 _IO_cookie_io_functions_t __io_functions;
357 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
358 _IO_cookie_io_functions_t io_functions);
361 /* Iterator type for walking global linked list of _IO_FILE objects. */
363 typedef struct _IO_FILE *_IO_ITER;
365 /* Generic functions */
367 extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
368 extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
369 extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
370 extern void _IO_init __P ((_IO_FILE *, int));
371 extern int _IO_sputbackc __P ((_IO_FILE *, int));
372 extern int _IO_sungetc __P ((_IO_FILE *));
373 extern void _IO_un_link __P ((struct _IO_FILE_plus *));
374 extern void _IO_link_in __P ((struct _IO_FILE_plus *));
375 extern void _IO_doallocbuf __P ((_IO_FILE *));
376 extern void _IO_unsave_markers __P ((_IO_FILE *));
377 extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
378 extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
379 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
381 extern void _IO_switch_to_main_wget_area __P ((_IO_FILE *));
382 extern void _IO_switch_to_wbackup_area __P ((_IO_FILE *));
383 extern int _IO_switch_to_wget_mode __P ((_IO_FILE *));
384 extern void _IO_wsetb __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
385 extern wint_t _IO_sputbackwc __P ((_IO_FILE *, wint_t));
386 extern wint_t _IO_sungetwc __P ((_IO_FILE *));
387 extern void _IO_wdoallocbuf __P ((_IO_FILE *));
388 extern void _IO_unsave_wmarkers __P ((_IO_FILE *));
389 extern unsigned _IO_adjust_wcolumn __P ((unsigned, const wchar_t *, int));
391 /* Marker-related function. */
393 extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
394 extern void _IO_init_wmarker __P ((struct _IO_marker *, _IO_FILE *));
395 extern void _IO_remove_marker __P ((struct _IO_marker *));
396 extern int _IO_marker_difference __P ((struct _IO_marker *,
397 struct _IO_marker *));
398 extern int _IO_marker_delta __P ((struct _IO_marker *));
399 extern int _IO_wmarker_delta __P ((struct _IO_marker *));
400 extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
401 extern int _IO_seekwmark __P ((_IO_FILE *, struct _IO_marker *, int));
403 /* Functions for iterating global list and dealing with
404 its lock */
406 extern _IO_ITER _IO_iter_begin __P ((void));
407 libc_hidden_proto (_IO_iter_begin)
408 extern _IO_ITER _IO_iter_end __P ((void));
409 libc_hidden_proto (_IO_iter_end)
410 extern _IO_ITER _IO_iter_next __P ((_IO_ITER));
411 libc_hidden_proto (_IO_iter_next)
412 extern _IO_FILE *_IO_iter_file __P ((_IO_ITER));
413 libc_hidden_proto (_IO_iter_file)
414 extern void _IO_list_lock __P ((void));
415 libc_hidden_proto (_IO_list_lock)
416 extern void _IO_list_unlock __P ((void));
417 libc_hidden_proto (_IO_list_unlock)
418 extern void _IO_list_resetlock __P ((void));
419 libc_hidden_proto (_IO_list_resetlock)
421 /* Default jumptable functions. */
423 extern int _IO_default_underflow __P ((_IO_FILE *));
424 extern int _IO_default_uflow __P ((_IO_FILE *));
425 extern wint_t _IO_wdefault_uflow __P ((_IO_FILE *));
426 extern int _IO_default_doallocate __P ((_IO_FILE *));
427 extern int _IO_wdefault_doallocate __P ((_IO_FILE *));
428 extern void _IO_default_finish __P ((_IO_FILE *, int));
429 extern void _IO_wdefault_finish __P ((_IO_FILE *, int));
430 extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
431 extern wint_t _IO_wdefault_pbackfail __P ((_IO_FILE *, wint_t));
432 extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
433 extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
434 _IO_size_t));
435 extern _IO_size_t _IO_wdefault_xsputn __P ((_IO_FILE *, const void *,
436 _IO_size_t));
437 extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
438 extern _IO_size_t _IO_wdefault_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
439 extern _IO_off64_t _IO_default_seekoff __P ((_IO_FILE *,
440 _IO_off64_t, int, int));
441 extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
442 extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
443 _IO_ssize_t));
444 extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
445 extern int _IO_default_stat __P ((_IO_FILE *, void *));
446 extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
447 extern int _IO_default_sync __P ((_IO_FILE *));
448 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
449 extern int _IO_default_showmanyc __P ((_IO_FILE *));
450 extern void _IO_default_imbue __P ((_IO_FILE *, void *));
452 extern struct _IO_jump_t _IO_file_jumps;
453 extern struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
454 extern struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
455 extern struct _IO_jump_t _IO_wfile_jumps attribute_hidden;
456 extern struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
457 extern struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
458 extern struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
459 extern struct _IO_jump_t _IO_streambuf_jumps;
460 extern struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
461 extern struct _IO_jump_t _IO_str_jumps attribute_hidden;
462 extern struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
463 extern struct _IO_codecvt __libio_codecvt attribute_hidden;
464 extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
465 extern int _IO_new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
466 extern int _IO_old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
467 extern int _IO_wdo_write __P ((_IO_FILE *, const wchar_t *, _IO_size_t));
468 extern int _IO_flush_all_lockp __P ((int));
469 extern int _IO_flush_all __P ((void));
470 extern int _IO_cleanup __P ((void));
471 extern void _IO_flush_all_linebuffered __P ((void));
472 extern int _IO_new_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
473 extern int _IO_old_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
474 extern int _IO_new_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
475 extern int _IO_old_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
476 extern int _IO_new_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
477 extern int _IO_old_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
478 extern int _IO_new_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
479 extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
482 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
483 # define _IO_do_flush(_f) \
484 ((_f)->_mode <= 0 \
485 ? INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
486 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
487 : INTUSE(_IO_wdo_write)(_f, (_f)->_wide_data->_IO_write_base, \
488 ((_f)->_wide_data->_IO_write_ptr \
489 - (_f)->_wide_data->_IO_write_base)))
490 #else
491 # define _IO_do_flush(_f) \
492 INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
493 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
494 #endif
496 #define _IO_old_do_flush(_f) \
497 _IO_old_do_write(_f, (_f)->_IO_write_base, \
498 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
499 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
500 #define _IO_mask_flags(fp, f, mask) \
501 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
502 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
503 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
504 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
505 (fp)->_wide_data->_IO_read_ptr = (g), \
506 (fp)->_wide_data->_IO_read_end = (eg))
507 #define _IO_setp(__fp, __p, __ep) \
508 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
509 = __p, (__fp)->_IO_write_end = (__ep))
510 #define _IO_wsetp(__fp, __p, __ep) \
511 ((__fp)->_wide_data->_IO_write_base \
512 = (__fp)->_wide_data->_IO_write_ptr = __p, \
513 (__fp)->_wide_data->_IO_write_end = (__ep))
514 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
515 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
516 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
517 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
518 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
519 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
520 - (fp)->_wide_data->_IO_buf_base)
522 /* Jumptable functions for files. */
524 extern int _IO_file_doallocate __P ((_IO_FILE *));
525 extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
526 extern _IO_off64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
527 extern _IO_off64_t _IO_file_seekoff_mmap __P ((_IO_FILE *, _IO_off64_t, int,
528 int));
529 extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
530 extern _IO_size_t _IO_file_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
531 extern int _IO_file_stat __P ((_IO_FILE *, void *));
532 extern int _IO_file_close __P ((_IO_FILE *));
533 extern int _IO_file_close_mmap __P ((_IO_FILE *));
534 extern int _IO_file_underflow __P ((_IO_FILE *));
535 extern int _IO_file_underflow_mmap __P ((_IO_FILE *));
536 extern int _IO_file_underflow_maybe_mmap __P ((_IO_FILE *));
537 extern int _IO_file_overflow __P ((_IO_FILE *, int));
538 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
539 extern void _IO_file_init __P ((struct _IO_FILE_plus *));
540 extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
541 extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
542 int, int));
543 libc_hidden_proto (_IO_file_open)
544 extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
545 int));
546 extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
547 _IO_ssize_t));
548 extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
549 extern int _IO_file_sync __P ((_IO_FILE *));
550 extern int _IO_file_close_it __P ((_IO_FILE *));
551 extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
552 extern void _IO_file_finish __P ((_IO_FILE *, int));
554 extern _IO_FILE* _IO_new_file_attach __P ((_IO_FILE *, int));
555 extern int _IO_new_file_close_it __P ((_IO_FILE *));
556 extern void _IO_new_file_finish __P ((_IO_FILE *, int));
557 extern _IO_FILE* _IO_new_file_fopen __P ((_IO_FILE *, const char *, const char *,
558 int));
559 extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
560 struct _IO_jump_t *));
561 extern void _IO_new_file_init __P ((struct _IO_FILE_plus *));
562 extern _IO_FILE* _IO_new_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
563 extern _IO_FILE* _IO_file_setbuf_mmap __P ((_IO_FILE *, char *, _IO_ssize_t));
564 extern int _IO_new_file_sync __P ((_IO_FILE *));
565 extern int _IO_new_file_underflow __P ((_IO_FILE *));
566 extern int _IO_new_file_overflow __P ((_IO_FILE *, int));
567 extern _IO_off64_t _IO_new_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
568 extern _IO_ssize_t _IO_new_file_write __P ((_IO_FILE *, const void *,
569 _IO_ssize_t));
570 extern _IO_size_t _IO_new_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
572 extern _IO_FILE* _IO_old_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
573 extern _IO_off64_t _IO_old_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int,
574 int));
575 extern _IO_size_t _IO_old_file_xsputn __P ((_IO_FILE *, const void *,
576 _IO_size_t));
577 extern int _IO_old_file_underflow __P ((_IO_FILE *));
578 extern int _IO_old_file_overflow __P ((_IO_FILE *, int));
579 extern void _IO_old_file_init __P ((struct _IO_FILE_plus *));
580 extern _IO_FILE* _IO_old_file_attach __P ((_IO_FILE *, int));
581 extern _IO_FILE* _IO_old_file_fopen __P ((_IO_FILE *, const char *,
582 const char *));
583 extern _IO_ssize_t _IO_old_file_write __P ((_IO_FILE *, const void *,
584 _IO_ssize_t));
585 extern int _IO_old_file_sync __P ((_IO_FILE *));
586 extern int _IO_old_file_close_it __P ((_IO_FILE *));
587 extern void _IO_old_file_finish __P ((_IO_FILE *, int));
589 extern int _IO_wfile_doallocate __P ((_IO_FILE *));
590 extern _IO_size_t _IO_wfile_xsputn __P ((_IO_FILE *, const void *,
591 _IO_size_t));
592 extern _IO_FILE* _IO_wfile_setbuf __P ((_IO_FILE *, wchar_t *, _IO_ssize_t));
593 extern wint_t _IO_wfile_sync __P ((_IO_FILE *));
594 extern wint_t _IO_wfile_underflow __P ((_IO_FILE *));
595 extern wint_t _IO_wfile_overflow __P ((_IO_FILE *, wint_t));
596 extern _IO_off64_t _IO_wfile_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
598 /* Jumptable functions for proc_files. */
599 extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
600 extern _IO_FILE* _IO_new_proc_open __P ((_IO_FILE *, const char *, const char *));
601 extern _IO_FILE* _IO_old_proc_open __P ((_IO_FILE *, const char *, const char *));
602 extern int _IO_proc_close __P ((_IO_FILE *));
603 extern int _IO_new_proc_close __P ((_IO_FILE *));
604 extern int _IO_old_proc_close __P ((_IO_FILE *));
606 /* Jumptable functions for strfiles. */
607 extern int _IO_str_underflow __P ((_IO_FILE *));
608 extern int _IO_str_overflow __P ((_IO_FILE *, int));
609 extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
610 extern _IO_off64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
611 extern void _IO_str_finish __P ((_IO_FILE *, int));
613 /* Other strfile functions */
614 struct _IO_strfile_;
615 extern void _IO_str_init_static __P ((struct _IO_strfile_ *, char *, int, char *));
616 extern void _IO_str_init_readonly __P ((struct _IO_strfile_ *, const char *, int));
617 extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
619 /* And the wide character versions. */
620 extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, int, wchar_t *));
621 extern void _IO_wstr_init_readonly __P ((_IO_FILE *, const char *, int));
622 extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
623 extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
624 extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
625 extern _IO_off64_t _IO_wstr_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
626 extern _IO_wint_t _IO_wstr_pbackfail __P ((_IO_FILE *, _IO_wint_t));
627 extern void _IO_wstr_finish __P ((_IO_FILE *, int));
629 extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
630 _IO_va_list args));
631 extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
632 extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
633 __const char *format, _IO_va_list args));
636 extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
637 extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
638 int, int, int *));
639 extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
640 extern _IO_size_t _IO_getwline __P ((_IO_FILE *,wchar_t *, _IO_size_t, wint_t,
641 int));
642 extern _IO_size_t _IO_getwline_info __P ((_IO_FILE *,wchar_t *, _IO_size_t,
643 wint_t, int, wint_t *));
644 extern double _IO_strtod __P ((const char *, char **));
645 extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
646 int *__decpt, int *__sign, char **__rve));
647 extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
648 int __width, int __precision, int __flags,
649 int __sign_mode, int __fill));
651 extern struct _IO_FILE_plus *_IO_list_all;
652 extern void (*_IO_cleanup_registration_needed) __PMT ((void));
654 /* Prototype for functions with alternative entry point. */
655 extern int _IO_flush_all_internal __P ((void));
656 extern unsigned _IO_adjust_column_internal __P ((unsigned, const char *, int));
658 extern int _IO_default_uflow_internal __P ((_IO_FILE *));
659 extern void _IO_default_finish_internal __P ((_IO_FILE *, int));
660 extern int _IO_default_pbackfail_internal __P ((_IO_FILE *, int));
661 extern _IO_size_t _IO_default_xsputn_internal __P ((_IO_FILE *, const void *,
662 _IO_size_t));
663 extern _IO_size_t _IO_default_xsgetn_internal __P ((_IO_FILE *, void *,
664 _IO_size_t));
665 extern int _IO_default_doallocate_internal __P ((_IO_FILE *));
666 extern void _IO_wdefault_finish_internal __P ((_IO_FILE *, int));
667 extern wint_t _IO_wdefault_pbackfail_internal __P ((_IO_FILE *, wint_t));
668 extern _IO_size_t _IO_wdefault_xsputn_internal __P ((_IO_FILE *, const void *,
669 _IO_size_t));
670 extern _IO_size_t _IO_wdefault_xsgetn_internal __P ((_IO_FILE *, void *,
671 _IO_size_t));
672 extern int _IO_wdefault_doallocate_internal __P ((_IO_FILE *));
673 extern wint_t _IO_wdefault_uflow_internal __P ((_IO_FILE *));
675 extern int _IO_file_doallocate_internal __P ((_IO_FILE *));
676 extern _IO_FILE* _IO_file_setbuf_internal __P ((_IO_FILE *, char *,
677 _IO_ssize_t));
678 extern _IO_off64_t _IO_file_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
679 int, int));
680 extern _IO_size_t _IO_file_xsputn_internal __P ((_IO_FILE *, const void *,
681 _IO_size_t));
682 extern _IO_size_t _IO_file_xsgetn_internal __P ((_IO_FILE *, void *,
683 _IO_size_t));
684 extern int _IO_file_stat_internal __P ((_IO_FILE *, void *));
685 extern int _IO_file_close_internal __P ((_IO_FILE *));
686 extern int _IO_file_close_it_internal __P ((_IO_FILE *));
687 extern int _IO_file_underflow_internal __P ((_IO_FILE *));
688 extern int _IO_file_overflow_internal __P ((_IO_FILE *, int));
689 extern void _IO_file_init_internal __P ((struct _IO_FILE_plus *));
690 extern _IO_FILE* _IO_file_attach_internal __P ((_IO_FILE *, int));
691 extern _IO_FILE* _IO_file_fopen_internal __P ((_IO_FILE *, const char *,
692 const char *, int));
693 extern _IO_ssize_t _IO_file_read_internal __P ((_IO_FILE *, void *,
694 _IO_ssize_t));
695 extern int _IO_file_sync_internal __P ((_IO_FILE *));
696 extern _IO_off64_t _IO_file_seek_internal __P ((_IO_FILE *, _IO_off64_t, int));
697 extern void _IO_file_finish_internal __P ((_IO_FILE *, int));
699 extern _IO_size_t _IO_wfile_xsputn_internal __P ((_IO_FILE *, const void *,
700 _IO_size_t));
701 extern _IO_off64_t _IO_wfile_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
702 int, int));
703 extern wint_t _IO_wfile_sync_internal __P ((_IO_FILE *));
705 extern int _IO_str_underflow_internal __P ((_IO_FILE *));
706 extern int _IO_str_overflow_internal __P ((_IO_FILE *, int));
707 extern int _IO_str_pbackfail_internal __P ((_IO_FILE *, int));
708 extern _IO_off64_t _IO_str_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
709 int, int));
710 extern void _IO_str_init_static_internal __P ((struct _IO_strfile_ *, char *,
711 int, char *));
713 extern struct _IO_jump_t _IO_file_jumps_internal attribute_hidden;
714 extern struct _IO_jump_t _IO_wfile_jumps_internal attribute_hidden;
716 extern struct _IO_FILE_plus *_IO_list_all_internal attribute_hidden;
718 extern void _IO_link_in_internal __P ((struct _IO_FILE_plus *));
719 extern int _IO_sputbackc_internal __P ((_IO_FILE *, int));
720 extern void _IO_wdoallocbuf_internal __P ((_IO_FILE *));
722 extern _IO_size_t _IO_sgetn_internal (_IO_FILE *, void *, _IO_size_t);
723 extern void _IO_flush_all_linebuffered_internal __P ((void));
724 extern int _IO_switch_to_wget_mode_internal __P ((_IO_FILE *));
725 extern void _IO_unsave_markers_internal __P ((_IO_FILE *));
726 extern void _IO_switch_to_main_wget_area_internal __P ((_IO_FILE *));
727 extern int _IO_wdo_write_internal __P ((_IO_FILE *, const wchar_t *,
728 _IO_size_t));
729 extern int _IO_do_write_internal __P ((_IO_FILE *, const char *, _IO_size_t));
730 extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t);
731 extern _IO_size_t _IO_getline_info_internal __P ((_IO_FILE *,char *,
732 _IO_size_t, int, int,
733 int *));
734 extern _IO_size_t _IO_getline_internal __P ((_IO_FILE *, char *, _IO_size_t,
735 int, int));
736 extern void _IO_free_wbackup_area_internal (_IO_FILE *);
737 extern void _IO_free_backup_area_internal (_IO_FILE *);
738 extern void _IO_switch_to_wbackup_area_internal __P ((_IO_FILE *));
739 extern void _IO_setb_internal __P ((_IO_FILE *, char *, char *, int));
740 extern wint_t _IO_sputbackwc_internal __P ((_IO_FILE *, wint_t));
741 extern int _IO_switch_to_get_mode_internal __P ((_IO_FILE *));
742 extern int _IO_vfscanf_internal (_IO_FILE * __restrict,
743 const char * __restrict,
744 _IO_va_list, int *__restrict);
745 extern int _IO_vfprintf_internal (_IO_FILE *__restrict, const char *__restrict,
746 _IO_va_list);
747 extern void _IO_doallocbuf_internal __P ((_IO_FILE *));
748 extern void _IO_wsetb_internal __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
749 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
750 attribute_hidden;
751 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
752 attribute_hidden;
753 extern int _IO_putc_internal (int __c, _IO_FILE *__fp);
754 extern void _IO_init_internal __P ((_IO_FILE *, int));
755 extern void _IO_un_link_internal __P ((struct _IO_FILE_plus *));
757 #ifndef EOF
758 # define EOF (-1)
759 #endif
760 #ifndef NULL
761 # if defined __GNUG__ && \
762 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
763 # define NULL (__null)
764 # else
765 # if !defined(__cplusplus)
766 # define NULL ((void*)0)
767 # else
768 # define NULL (0)
769 # endif
770 # endif
771 #endif
773 #if _G_HAVE_MMAP
775 # include <unistd.h>
776 # include <fcntl.h>
777 # include <sys/mman.h>
778 # include <sys/param.h>
780 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
781 # define MAP_ANONYMOUS MAP_ANON
782 # endif
784 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
785 # undef _G_HAVE_MMAP
786 # define _G_HAVE_MMAP 0
787 # endif
789 #endif /* _G_HAVE_MMAP */
791 #if _G_HAVE_MMAP
793 # ifdef _LIBC
794 /* When using this code in the GNU libc we must not pollute the name space. */
795 # define mmap __mmap
796 # define munmap __munmap
797 # define ftruncate __ftruncate
798 # endif
800 # define ROUND_TO_PAGE(_S) \
801 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
803 # define FREE_BUF(_B, _S) \
804 munmap ((_B), ROUND_TO_PAGE (_S))
805 # define ALLOC_BUF(_B, _S, _R) \
806 do { \
807 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
808 PROT_READ | PROT_WRITE, \
809 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
810 if ((_B) == (char *) MAP_FAILED) \
811 return (_R); \
812 } while (0)
813 # define ALLOC_WBUF(_B, _S, _R) \
814 do { \
815 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
816 PROT_READ | PROT_WRITE, \
817 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
818 if ((_B) == (wchar_t *) MAP_FAILED) \
819 return (_R); \
820 } while (0)
822 #else /* _G_HAVE_MMAP */
824 # define FREE_BUF(_B, _S) \
825 free(_B)
826 # define ALLOC_BUF(_B, _S, _R) \
827 do { \
828 (_B) = (char*)malloc(_S); \
829 if ((_B) == NULL) \
830 return (_R); \
831 } while (0)
832 # define ALLOC_WBUF(_B, _S, _R) \
833 do { \
834 (_B) = (wchar_t *)malloc(_S); \
835 if ((_B) == NULL) \
836 return (_R); \
837 } while (0)
839 #endif /* _G_HAVE_MMAP */
841 #ifndef OS_FSTAT
842 # define OS_FSTAT fstat
843 #endif
844 struct stat;
845 extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
846 extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
847 extern _IO_off64_t _IO_lseek __P ((int, _IO_off64_t, int));
848 extern int _IO_close __P ((int));
849 extern int _IO_fstat __P ((int, struct stat *));
850 extern int _IO_vscanf __P ((const char *, _IO_va_list));
852 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
853 #ifndef _IO_pos_BAD
854 # define _IO_pos_BAD ((_IO_off64_t) -1)
855 #endif
856 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
857 #ifndef _IO_pos_adjust
858 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
859 #endif
860 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
861 #ifndef _IO_pos_0
862 # define _IO_pos_0 ((_IO_off64_t) 0)
863 #endif
865 #ifdef __cplusplus
867 #endif
869 #ifdef _IO_MTSAFE_IO
870 /* check following! */
871 # ifdef _IO_USE_OLD_IO_FILE
872 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
873 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
874 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
875 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
876 # else
877 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
878 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
879 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
880 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
881 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
882 NULL, WDP, 0 }
883 # else
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, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
889 # endif
890 # endif
891 #else
892 # ifdef _IO_USE_OLD_IO_FILE
893 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
894 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
895 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
896 0, _IO_pos_BAD }
897 # else
898 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
899 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
900 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
901 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
902 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
903 NULL, WDP, 0 }
904 # else
905 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
906 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
907 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
908 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
910 # endif
911 # endif
912 #endif
914 /* VTABLE_LABEL defines NAME as of the CLASS class.
915 CNLENGTH is strlen(#CLASS). */
916 #ifdef __GNUC__
917 # if _G_VTABLE_LABEL_HAS_LENGTH
918 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
919 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
920 # else
921 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
922 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
923 # endif
924 #endif /* __GNUC__ */
926 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
927 # ifdef __GNUC__
928 VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
929 # else
930 # if _G_VTABLE_LABEL_HAS_LENGTH
931 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
932 # else
933 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
934 # endif
935 # endif
936 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
938 #if defined(__STDC__) || defined(__cplusplus)
939 # define _IO_va_start(args, last) va_start(args, last)
940 #else
941 # define _IO_va_start(args, last) va_start(args)
942 #endif
944 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
946 #if 1
947 # define COERCE_FILE(FILE) /* Nothing */
948 #else
949 /* This is part of the kludge for binary compatibility with old stdio. */
950 # define COERCE_FILE(FILE) \
951 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
952 && (FILE) = *(FILE**)&((int*)fp)[1])
953 #endif
955 #ifdef EINVAL
956 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
957 #else
958 # define MAYBE_SET_EINVAL /* nothing */
959 #endif
961 #ifdef IO_DEBUG
962 # define CHECK_FILE(FILE, RET) \
963 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
964 else { COERCE_FILE(FILE); \
965 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
966 { MAYBE_SET_EINVAL; return RET; }}
967 #else
968 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
969 #endif
971 #endif /* _LIBIO_P_H_ */