Setup LOCPATH for tst-ftell-active-handler and tst-ftell-partial-wide in libio
[platform/upstream/glibc.git] / libio / libioP.h
1 /* Copyright (C) 1993-2014 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, see
16    <http://www.gnu.org/licenses/>.
17
18    As a special exception, if you link the code in this file with
19    files compiled with a GNU compiler to produce an executable,
20    that does not cause the resulting executable to be covered by
21    the GNU Lesser General Public License.  This exception does not
22    however invalidate any other reasons why the executable file
23    might be covered by the GNU Lesser General Public License.
24    This exception applies to code released by its copyright holders
25    in files containing the exception.  */
26
27 /* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
28    own implementation.  As a result, functions that were implemented for C++
29    (like *sputn) may no longer have C++ semantics.  This is of course only
30    relevant for internal callers of these functions since these functions are
31    not intended for external use otherwise.
32
33    FIXME: All of the C++ cruft eventually needs to go away.  */
34
35 #include <errno.h>
36 #ifndef __set_errno
37 # define __set_errno(Val) errno = (Val)
38 #endif
39 #if defined __GLIBC__ && __GLIBC__ >= 2
40 # include <bits/libc-lock.h>
41 #else
42 /*# include <comthread.h>*/
43 #endif
44
45 #include <math_ldbl_opt.h>
46
47 #include "iolibio.h"
48
49 /* Control of exported symbols.  Used in glibc.  By default we don't
50    do anything.  */
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
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 #define _IO_seek_set 0
66 #define _IO_seek_cur 1
67 #define _IO_seek_end 2
68
69 /* THE JUMPTABLE FUNCTIONS.
70
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 an 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.
83  *
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).
88  */
89
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
99
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
104
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)
108
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 #define JUMP_FIELD(TYPE, NAME) TYPE NAME
120 #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
121 #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
122 #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
123 #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
124 #define JUMP_INIT(NAME, VALUE) VALUE
125 #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
126
127 #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
128 #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
129 #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
130 #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
131
132 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
133    It does not delete (free) it, but does everything else to finalize it.
134    It matches the streambuf::~streambuf virtual destructor.  */
135 typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
136 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
137 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
138
139 /* The 'overflow' hook flushes the buffer.
140    The second argument is a character, or EOF.
141    It matches the streambuf::overflow virtual function. */
142 typedef int (*_IO_overflow_t) (_IO_FILE *, int);
143 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
144 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
145
146 /* The 'underflow' hook tries to fills the get buffer.
147    It returns the next character (as an unsigned char) or EOF.  The next
148    character remains in the get buffer, and the get position is not changed.
149    It matches the streambuf::underflow virtual function. */
150 typedef int (*_IO_underflow_t) (_IO_FILE *);
151 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
152 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
153
154 /* The 'uflow' hook returns the next character in the input stream
155    (cast to unsigned char), and increments the read position;
156    EOF is returned on failure.
157    It matches the streambuf::uflow virtual function, which is not in the
158    cfront implementation, but was added to C++ by the ANSI/ISO committee. */
159 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
160 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
161
162 /* The 'pbackfail' hook handles backing up.
163    It matches the streambuf::pbackfail virtual function. */
164 typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
165 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
166 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
167
168 /* The 'xsputn' hook writes upto N characters from buffer DATA.
169    Returns EOF or the number of character actually written.
170    It matches the streambuf::xsputn virtual function. */
171 typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
172                                     _IO_size_t N);
173 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
174 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
175
176 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
177    Returns the number of character actually read.
178    It matches the streambuf::xsgetn virtual function. */
179 typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
180 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
181 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
182
183 /* The 'seekoff' hook moves the stream position to a new position
184    relative to the start of the file (if DIR==0), the current position
185    (MODE==1), or the end of the file (MODE==2).
186    It matches the streambuf::seekoff virtual function.
187    It is also used for the ANSI fseek function. */
188 typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
189                                       int MODE);
190 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
191 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
192
193 /* The 'seekpos' hook also moves the stream position,
194    but to an absolute position given by a fpos64_t (seekpos).
195    It matches the streambuf::seekpos virtual function.
196    It is also used for the ANSI fgetpos and fsetpos functions.  */
197 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
198 typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
199 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
200 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
201
202 /* The 'setbuf' hook gives a buffer to the file.
203    It matches the streambuf::setbuf virtual function. */
204 typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
205 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
206 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
207
208 /* The 'sync' hook attempts to synchronize the internal data structures
209    of the file with the external state.
210    It matches the streambuf::sync virtual function. */
211 typedef int (*_IO_sync_t) (_IO_FILE *);
212 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
213 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
214
215 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
216    It matches the streambuf::doallocate virtual function, which is not
217    in the ANSI/ISO C++ standard, but is part traditional implementations. */
218 typedef int (*_IO_doallocate_t) (_IO_FILE *);
219 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
220 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
221
222 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
223    sysstat) are low-level hooks specific to this implementation.
224    There is no correspondence in the ANSI/ISO C++ standard library.
225    The hooks basically correspond to the Unix system functions
226    (read, write, close, lseek, and stat) except that a _IO_FILE*
227    parameter is used instead of an integer file descriptor;  the default
228    implementation used for normal files just calls those functions.
229    The advantage of overriding these functions instead of the higher-level
230    ones (underflow, overflow etc) is that you can leave all the buffering
231    higher-level functions.  */
232
233 /* The 'sysread' hook is used to read data from the external file into
234    an existing buffer.  It generalizes the Unix read(2) function.
235    It matches the streambuf::sys_read virtual function, which is
236    specific to this implementation. */
237 typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
238 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
239 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
240
241 /* The 'syswrite' hook is used to write data from an existing buffer
242    to an external file.  It generalizes the Unix write(2) function.
243    It matches the streambuf::sys_write virtual function, which is
244    specific to this implementation. */
245 typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
246 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
247 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
248
249 /* The 'sysseek' hook is used to re-position an external file.
250    It generalizes the Unix lseek(2) function.
251    It matches the streambuf::sys_seek virtual function, which is
252    specific to this implementation. */
253 typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
254 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
255 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
256
257 /* The 'sysclose' hook is used to finalize (close, finish up) an
258    external file.  It generalizes the Unix close(2) function.
259    It matches the streambuf::sys_close virtual function, which is
260    specific to this implementation. */
261 typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
262 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
263 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
264
265 /* The 'sysstat' hook is used to get information about an external file
266    into a struct stat buffer.  It generalizes the Unix fstat(2) call.
267    It matches the streambuf::sys_stat virtual function, which is
268    specific to this implementation. */
269 typedef int (*_IO_stat_t) (_IO_FILE *, void *);
270 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
271 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
272
273 /* The 'showmany' hook can be used to get an image how much input is
274    available.  In many cases the answer will be 0 which means unknown
275    but some cases one can provide real information.  */
276 typedef int (*_IO_showmanyc_t) (_IO_FILE *);
277 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
278 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
279
280 /* The 'imbue' hook is used to get information about the currently
281    installed locales.  */
282 typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
283 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
284 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
285
286
287 #define _IO_CHAR_TYPE char /* unsigned char ? */
288 #define _IO_INT_TYPE int
289
290 struct _IO_jump_t
291 {
292     JUMP_FIELD(size_t, __dummy);
293     JUMP_FIELD(size_t, __dummy2);
294     JUMP_FIELD(_IO_finish_t, __finish);
295     JUMP_FIELD(_IO_overflow_t, __overflow);
296     JUMP_FIELD(_IO_underflow_t, __underflow);
297     JUMP_FIELD(_IO_underflow_t, __uflow);
298     JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
299     /* showmany */
300     JUMP_FIELD(_IO_xsputn_t, __xsputn);
301     JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
302     JUMP_FIELD(_IO_seekoff_t, __seekoff);
303     JUMP_FIELD(_IO_seekpos_t, __seekpos);
304     JUMP_FIELD(_IO_setbuf_t, __setbuf);
305     JUMP_FIELD(_IO_sync_t, __sync);
306     JUMP_FIELD(_IO_doallocate_t, __doallocate);
307     JUMP_FIELD(_IO_read_t, __read);
308     JUMP_FIELD(_IO_write_t, __write);
309     JUMP_FIELD(_IO_seek_t, __seek);
310     JUMP_FIELD(_IO_close_t, __close);
311     JUMP_FIELD(_IO_stat_t, __stat);
312     JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
313     JUMP_FIELD(_IO_imbue_t, __imbue);
314 #if 0
315     get_column;
316     set_column;
317 #endif
318 };
319
320 /* We always allocate an extra word following an _IO_FILE.
321    This contains a pointer to the function jump table used.
322    This is for compatibility with C++ streambuf; the word can
323    be used to smash to a pointer to a virtual function table. */
324
325 struct _IO_FILE_plus
326 {
327   _IO_FILE file;
328   const struct _IO_jump_t *vtable;
329 };
330
331 #ifdef _IO_USE_OLD_IO_FILE
332 /* This structure is used by the compatibility code as if it were an
333    _IO_FILE_plus, but has enough space to initialize the _mode argument
334    of an _IO_FILE_complete.  */
335 struct _IO_FILE_complete_plus
336 {
337   struct _IO_FILE_complete file;
338   const struct _IO_jump_t *vtable;
339 };
340 #endif
341
342 /* Special file type for fopencookie function.  */
343 struct _IO_cookie_file
344 {
345   struct _IO_FILE_plus __fp;
346   void *__cookie;
347   _IO_cookie_io_functions_t __io_functions;
348 };
349
350 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
351                            _IO_cookie_io_functions_t io_functions);
352
353
354 /* Iterator type for walking global linked list of _IO_FILE objects. */
355
356 typedef struct _IO_FILE *_IO_ITER;
357
358 /* Generic functions */
359
360 extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
361 extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
362 extern int _IO_switch_to_get_mode (_IO_FILE *);
363 libc_hidden_proto (_IO_switch_to_get_mode)
364 extern void _IO_init (_IO_FILE *, int) __THROW;
365 libc_hidden_proto (_IO_init)
366 extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
367 libc_hidden_proto (_IO_sputbackc)
368 extern int _IO_sungetc (_IO_FILE *) __THROW;
369 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
370 libc_hidden_proto (_IO_un_link)
371 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
372 libc_hidden_proto (_IO_link_in)
373 extern void _IO_doallocbuf (_IO_FILE *) __THROW;
374 libc_hidden_proto (_IO_doallocbuf)
375 extern void _IO_unsave_markers (_IO_FILE *) __THROW;
376 libc_hidden_proto (_IO_unsave_markers)
377 extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
378 libc_hidden_proto (_IO_setb)
379 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
380 libc_hidden_proto (_IO_adjust_column)
381 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
382
383 _IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
384 libc_hidden_proto (_IO_least_wmarker)
385 extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
386 libc_hidden_proto (_IO_switch_to_main_wget_area)
387 extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
388 libc_hidden_proto (_IO_switch_to_wbackup_area)
389 extern int _IO_switch_to_wget_mode (_IO_FILE *);
390 libc_hidden_proto (_IO_switch_to_wget_mode)
391 extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
392 libc_hidden_proto (_IO_wsetb)
393 extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
394 libc_hidden_proto (_IO_sputbackwc)
395 extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
396 extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
397 libc_hidden_proto (_IO_wdoallocbuf)
398 extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
399 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
400 extern _IO_off64_t get_file_offset (_IO_FILE *fp);
401
402 /* Marker-related function. */
403
404 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
405 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
406 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
407 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
408      __THROW;
409 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
410 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
411 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
412 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
413
414 /* Functions for iterating global list and dealing with its lock */
415
416 extern _IO_ITER _IO_iter_begin (void) __THROW;
417 libc_hidden_proto (_IO_iter_begin)
418 extern _IO_ITER _IO_iter_end (void) __THROW;
419 libc_hidden_proto (_IO_iter_end)
420 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
421 libc_hidden_proto (_IO_iter_next)
422 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
423 libc_hidden_proto (_IO_iter_file)
424 extern void _IO_list_lock (void) __THROW;
425 libc_hidden_proto (_IO_list_lock)
426 extern void _IO_list_unlock (void) __THROW;
427 libc_hidden_proto (_IO_list_unlock)
428 extern void _IO_list_resetlock (void) __THROW;
429 libc_hidden_proto (_IO_list_resetlock)
430
431 /* Default jumptable functions. */
432
433 extern int _IO_default_underflow (_IO_FILE *) __THROW;
434 extern int _IO_default_uflow (_IO_FILE *);
435 libc_hidden_proto (_IO_default_uflow)
436 extern wint_t _IO_wdefault_uflow (_IO_FILE *);
437 libc_hidden_proto (_IO_wdefault_uflow)
438 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
439 libc_hidden_proto (_IO_default_doallocate)
440 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
441 libc_hidden_proto (_IO_wdefault_doallocate)
442 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
443 libc_hidden_proto (_IO_default_finish)
444 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
445 libc_hidden_proto (_IO_wdefault_finish)
446 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
447 libc_hidden_proto (_IO_default_pbackfail)
448 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
449 libc_hidden_proto (_IO_wdefault_pbackfail)
450 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
451 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
452 libc_hidden_proto (_IO_default_xsputn)
453 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
454 libc_hidden_proto (_IO_wdefault_xsputn)
455 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
456 libc_hidden_proto (_IO_default_xsgetn)
457 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
458 libc_hidden_proto (_IO_wdefault_xsgetn)
459 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
460      __THROW;
461 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
462 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
463 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
464 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
465 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
466 extern int _IO_default_sync (_IO_FILE *) __THROW;
467 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
468 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
469 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
470
471 extern const struct _IO_jump_t _IO_file_jumps;
472 libc_hidden_proto (_IO_file_jumps)
473 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
474 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
475 extern const struct _IO_jump_t _IO_wfile_jumps;
476 libc_hidden_proto (_IO_wfile_jumps)
477 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
478 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
479 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
480 extern const struct _IO_jump_t _IO_streambuf_jumps;
481 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
482 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
483 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
484 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
485 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
486 libc_hidden_proto (_IO_do_write)
487 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
488 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
489 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
490 libc_hidden_proto (_IO_wdo_write)
491 extern int _IO_flush_all_lockp (int);
492 extern int _IO_flush_all (void);
493 libc_hidden_proto (_IO_flush_all)
494 extern int _IO_cleanup (void);
495 extern void _IO_flush_all_linebuffered (void);
496 libc_hidden_proto (_IO_flush_all_linebuffered)
497 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
498 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
499 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
500 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
501 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
502 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
503 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
504 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
505 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
506
507
508 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
509 # define _IO_do_flush(_f) \
510   ((_f)->_mode <= 0                                                           \
511    ? _IO_do_write(_f, (_f)->_IO_write_base,                                   \
512                   (_f)->_IO_write_ptr-(_f)->_IO_write_base)                   \
513    : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base,                      \
514                    ((_f)->_wide_data->_IO_write_ptr                           \
515                     - (_f)->_wide_data->_IO_write_base)))
516 #else
517 # define _IO_do_flush(_f) \
518   _IO_do_write(_f, (_f)->_IO_write_base,                                      \
519                (_f)->_IO_write_ptr-(_f)->_IO_write_base)
520 #endif
521 #define _IO_old_do_flush(_f) \
522   _IO_old_do_write(_f, (_f)->_IO_write_base, \
523                    (_f)->_IO_write_ptr-(_f)->_IO_write_base)
524 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
525 #define _IO_mask_flags(fp, f, mask) \
526        ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
527 #define _IO_setg(fp, eb, g, eg)  ((fp)->_IO_read_base = (eb),\
528         (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
529 #define _IO_wsetg(fp, eb, g, eg)  ((fp)->_wide_data->_IO_read_base = (eb),\
530         (fp)->_wide_data->_IO_read_ptr = (g), \
531         (fp)->_wide_data->_IO_read_end = (eg))
532 #define _IO_setp(__fp, __p, __ep) \
533        ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
534         = __p, (__fp)->_IO_write_end = (__ep))
535 #define _IO_wsetp(__fp, __p, __ep) \
536        ((__fp)->_wide_data->_IO_write_base \
537         = (__fp)->_wide_data->_IO_write_ptr = __p, \
538         (__fp)->_wide_data->_IO_write_end = (__ep))
539 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
540 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
541 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
542 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
543 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
544 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
545                        - (fp)->_wide_data->_IO_buf_base)
546
547 /* Jumptable functions for files. */
548
549 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
550 libc_hidden_proto (_IO_file_doallocate)
551 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
552 libc_hidden_proto (_IO_file_setbuf)
553 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
554 libc_hidden_proto (_IO_file_seekoff)
555 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
556      __THROW;
557 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
558 libc_hidden_proto (_IO_file_xsputn)
559 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
560 libc_hidden_proto (_IO_file_xsgetn)
561 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
562 libc_hidden_proto (_IO_file_stat)
563 extern int _IO_file_close (_IO_FILE *) __THROW;
564 libc_hidden_proto (_IO_file_close)
565 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
566 extern int _IO_file_underflow (_IO_FILE *);
567 libc_hidden_proto (_IO_file_underflow)
568 extern int _IO_file_underflow_mmap (_IO_FILE *);
569 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
570 extern int _IO_file_overflow (_IO_FILE *, int);
571 libc_hidden_proto (_IO_file_overflow)
572 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
573 extern void _IO_file_init (struct _IO_FILE_plus *) __THROW;
574 libc_hidden_proto (_IO_file_init)
575 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
576 libc_hidden_proto (_IO_file_attach)
577 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
578 libc_hidden_proto (_IO_file_open)
579 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
580 libc_hidden_proto (_IO_file_fopen)
581 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
582 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
583 libc_hidden_proto (_IO_file_read)
584 extern int _IO_file_sync (_IO_FILE *);
585 libc_hidden_proto (_IO_file_sync)
586 extern int _IO_file_close_it (_IO_FILE *);
587 libc_hidden_proto (_IO_file_close_it)
588 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
589 libc_hidden_proto (_IO_file_seek)
590 extern void _IO_file_finish (_IO_FILE *, int);
591 libc_hidden_proto (_IO_file_finish)
592
593 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
594 extern int _IO_new_file_close_it (_IO_FILE *);
595 extern void _IO_new_file_finish (_IO_FILE *, int);
596 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
597                                      int);
598 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
599                          const struct _IO_jump_t *) __THROW;
600 extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW;
601 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
602 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
603 extern int _IO_new_file_sync (_IO_FILE *);
604 extern int _IO_new_file_underflow (_IO_FILE *);
605 extern int _IO_new_file_overflow (_IO_FILE *, int);
606 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
607 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
608 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
609
610 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
611 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
612 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
613 extern int _IO_old_file_underflow (_IO_FILE *);
614 extern int _IO_old_file_overflow (_IO_FILE *, int);
615 extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW;
616 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
617 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
618 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
619 extern int _IO_old_file_sync (_IO_FILE *);
620 extern int _IO_old_file_close_it (_IO_FILE *);
621 extern void _IO_old_file_finish (_IO_FILE *, int);
622
623 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
624 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
625 libc_hidden_proto (_IO_wfile_xsputn)
626 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
627 extern wint_t _IO_wfile_sync (_IO_FILE *);
628 libc_hidden_proto (_IO_wfile_sync)
629 extern wint_t _IO_wfile_underflow (_IO_FILE *);
630 libc_hidden_proto (_IO_wfile_underflow)
631 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
632 libc_hidden_proto (_IO_wfile_overflow)
633 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
634 libc_hidden_proto (_IO_wfile_seekoff)
635
636 /* Jumptable functions for proc_files. */
637 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
638      __THROW;
639 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
640      __THROW;
641 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
642 extern int _IO_proc_close (_IO_FILE *) __THROW;
643 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
644 extern int _IO_old_proc_close (_IO_FILE *);
645
646 /* Jumptable functions for strfiles. */
647 extern int _IO_str_underflow (_IO_FILE *) __THROW;
648 libc_hidden_proto (_IO_str_underflow)
649 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
650 libc_hidden_proto (_IO_str_overflow)
651 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
652 libc_hidden_proto (_IO_str_pbackfail)
653 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
654 libc_hidden_proto (_IO_str_seekoff)
655 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
656
657 /* Other strfile functions */
658 struct _IO_strfile_;
659 extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *)
660      __THROW;
661 extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int)
662      __THROW;
663 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
664
665 /* And the wide character versions.  */
666 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
667      __THROW;
668 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
669 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
670 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
671 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
672      __THROW;
673 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
674 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
675
676 extern int _IO_vasprintf (char **result_ptr, const char *format,
677                           _IO_va_list args) __THROW;
678 extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
679 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
680                           const char *format, _IO_va_list args) __THROW;
681
682
683 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
684 libc_hidden_proto (_IO_getline)
685 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
686                                     int, int, int *);
687 libc_hidden_proto (_IO_getline_info)
688 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
689 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
690 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
691                                      wint_t, int, wint_t *);
692
693 extern struct _IO_FILE_plus *_IO_list_all;
694 libc_hidden_proto (_IO_list_all)
695 extern void (*_IO_cleanup_registration_needed) (void);
696
697 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
698                                           _IO_size_t, char *) __THROW;
699 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
700      attribute_hidden;
701 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
702      attribute_hidden;
703
704 #ifndef EOF
705 # define EOF (-1)
706 #endif
707 #ifndef NULL
708 # if defined __GNUG__ && \
709     (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
710 #  define NULL (__null)
711 # else
712 #  if !defined(__cplusplus)
713 #   define NULL ((void*)0)
714 #  else
715 #   define NULL (0)
716 #  endif
717 # endif
718 #endif
719
720 #if _G_HAVE_MMAP
721
722 # include <unistd.h>
723 # include <fcntl.h>
724 # include <sys/mman.h>
725 # include <sys/param.h>
726
727 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
728 #  define MAP_ANONYMOUS MAP_ANON
729 # endif
730
731 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
732 #  undef _G_HAVE_MMAP
733 #  define _G_HAVE_MMAP 0
734 # endif
735
736 #endif /* _G_HAVE_MMAP */
737
738 #if _G_HAVE_MMAP
739
740 # ifdef _LIBC
741 /* When using this code in the GNU libc we must not pollute the name space.  */
742 #  define mmap __mmap
743 #  define munmap __munmap
744 #  define ftruncate __ftruncate
745 # endif
746
747 # define ROUND_TO_PAGE(_S) \
748        (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
749
750 # define FREE_BUF(_B, _S) \
751        munmap ((_B), ROUND_TO_PAGE (_S))
752 # define ALLOC_BUF(_B, _S, _R) \
753        do {                                                                   \
754           (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S),                        \
755                                 PROT_READ | PROT_WRITE,                       \
756                                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);          \
757           if ((_B) == (char *) MAP_FAILED)                                    \
758             return (_R);                                                      \
759        } while (0)
760 # define ALLOC_WBUF(_B, _S, _R) \
761        do {                                                                   \
762           (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S),                     \
763                                    PROT_READ | PROT_WRITE,                    \
764                                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);       \
765           if ((_B) == (wchar_t *) MAP_FAILED)                                 \
766             return (_R);                                                      \
767        } while (0)
768
769 #else /* _G_HAVE_MMAP */
770
771 # define FREE_BUF(_B, _S) \
772        free(_B)
773 # define ALLOC_BUF(_B, _S, _R) \
774        do {                                                                   \
775           (_B) = (char*)malloc(_S);                                           \
776           if ((_B) == NULL)                                                   \
777             return (_R);                                                      \
778        } while (0)
779 # define ALLOC_WBUF(_B, _S, _R) \
780        do {                                                                   \
781           (_B) = (wchar_t *)malloc(_S);                                       \
782           if ((_B) == NULL)                                                   \
783             return (_R);                                                      \
784        } while (0)
785
786 #endif /* _G_HAVE_MMAP */
787
788 #ifndef OS_FSTAT
789 # define OS_FSTAT fstat
790 #endif
791 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
792
793 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
794 #ifndef _IO_pos_BAD
795 # define _IO_pos_BAD ((_IO_off64_t) -1)
796 #endif
797 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
798 #ifndef _IO_pos_adjust
799 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
800 #endif
801 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
802 #ifndef _IO_pos_0
803 # define _IO_pos_0 ((_IO_off64_t) 0)
804 #endif
805
806 #ifdef __cplusplus
807 }
808 #endif
809
810 #ifdef _IO_MTSAFE_IO
811 /* check following! */
812 # ifdef _IO_USE_OLD_IO_FILE
813 #  define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
814        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
815          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
816          0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
817 # else
818 #  if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
819 #   define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
820        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
821          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
822          0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
823          NULL, WDP, 0 }
824 #  else
825 #   define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
826        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
827          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
828          0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
829          0 }
830 #  endif
831 # endif
832 #else
833 # ifdef _IO_USE_OLD_IO_FILE
834 #  define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
835        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
836          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
837          0, _IO_pos_BAD }
838 # else
839 #  if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
840 #   define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
841        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
842          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
843          0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
844          NULL, WDP, 0 }
845 #  else
846 #   define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
847        { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
848          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
849          0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
850          0 }
851 #  endif
852 # endif
853 #endif
854
855 #define _IO_va_start(args, last) va_start(args, last)
856
857 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
858
859 #if 1
860 # define COERCE_FILE(FILE) /* Nothing */
861 #else
862 /* This is part of the kludge for binary compatibility with old stdio. */
863 # define COERCE_FILE(FILE) \
864   (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
865     && (FILE) = *(FILE**)&((int*)fp)[1])
866 #endif
867
868 #ifdef EINVAL
869 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
870 #else
871 # define MAYBE_SET_EINVAL /* nothing */
872 #endif
873
874 #ifdef IO_DEBUG
875 # define CHECK_FILE(FILE, RET) \
876         if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
877         else { COERCE_FILE(FILE); \
878                if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
879           { MAYBE_SET_EINVAL; return RET; }}
880 #else
881 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
882 #endif
883
884 static inline void
885 __attribute__ ((__always_inline__))
886 _IO_acquire_lock_fct (_IO_FILE **p)
887 {
888   _IO_FILE *fp = *p;
889   if ((fp->_flags & _IO_USER_LOCK) == 0)
890     _IO_funlockfile (fp);
891 }
892
893 static inline void
894 __attribute__ ((__always_inline__))
895 _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
896 {
897   _IO_FILE *fp = *p;
898   fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
899   if ((fp->_flags & _IO_USER_LOCK) == 0)
900     _IO_funlockfile (fp);
901 }
902
903 #if !defined _IO_MTSAFE_IO && !defined NOT_IN_libc
904 # define _IO_acquire_lock(_fp)                                                \
905   do {                                                                        \
906     _IO_FILE *_IO_acquire_lock_file = NULL
907 # define _IO_acquire_lock_clear_flags2(_fp)                                   \
908   do {                                                                        \
909     _IO_FILE *_IO_acquire_lock_file = (_fp)
910 # define _IO_release_lock(_fp)                                                \
911     if (_IO_acquire_lock_file != NULL)                                        \
912       _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY                  \
913                                           | _IO_FLAGS2_SCANF_STD);            \
914   } while (0)
915 #endif