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