Update copyright notices with scripts/update-copyrights
[glibc.git] / libio / libioP.h
blob4ca723c977a61a162ff17602657da43540d446fb
1 /* Copyright (C) 1993-2014 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, see
16 <http://www.gnu.org/licenses/>.
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. */
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.
33 FIXME: All of the C++ cruft eventually needs to go away. */
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
45 #include <math_ldbl_opt.h>
47 #include "iolibio.h"
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
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 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.
84 * The entries in the _IO_JUMPS function table (and hence also the
85 * virtual functions of a streambuf) are described below.
86 * The first parameter of each function entry is the _IO_FILE/streambuf
87 * object being acted on (i.e. the 'this' parameter).
90 #ifdef _LIBC
91 # include <shlib-compat.h>
92 # if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
93 /* Setting this macro disables the use of the _vtable_offset
94 bias in _IO_JUMPS_FUNCS, below. That is only needed if we
95 want to support old binaries (see oldfileops.c). */
96 # define _G_IO_NO_BACKWARD_COMPAT 1
97 # endif
98 #endif
100 #if (!defined _IO_USE_OLD_IO_FILE \
101 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
102 # define _IO_JUMPS_OFFSET 1
103 #endif
105 #define _IO_JUMPS(THIS) (THIS)->vtable
106 #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
107 #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
109 #if _IO_JUMPS_OFFSET
110 # define _IO_JUMPS_FUNC(THIS) \
111 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
112 + (THIS)->_vtable_offset))
113 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
114 #else
115 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
116 # define _IO_vtable_offset(THIS) 0
117 #endif
118 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
119 #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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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. */
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)
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)
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)
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)
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)
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)
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)
287 #define _IO_CHAR_TYPE char /* unsigned char ? */
288 #define _IO_INT_TYPE int
290 struct _IO_jump_t
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
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. */
325 struct _IO_FILE_plus
327 _IO_FILE file;
328 const struct _IO_jump_t *vtable;
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
337 struct _IO_FILE_complete file;
338 const struct _IO_jump_t *vtable;
340 #endif
342 /* Special file type for fopencookie function. */
343 struct _IO_cookie_file
345 struct _IO_FILE_plus __fp;
346 void *__cookie;
347 _IO_cookie_io_functions_t __io_functions;
350 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
351 _IO_cookie_io_functions_t io_functions);
354 /* Iterator type for walking global linked list of _IO_FILE objects. */
356 typedef struct _IO_FILE *_IO_ITER;
358 /* Generic functions */
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)
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;
401 /* Marker-related function. */
403 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
404 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
405 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
406 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
407 __THROW;
408 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
409 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
410 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
411 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
413 /* Functions for iterating global list and dealing with its lock */
415 extern _IO_ITER _IO_iter_begin (void) __THROW;
416 libc_hidden_proto (_IO_iter_begin)
417 extern _IO_ITER _IO_iter_end (void) __THROW;
418 libc_hidden_proto (_IO_iter_end)
419 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
420 libc_hidden_proto (_IO_iter_next)
421 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
422 libc_hidden_proto (_IO_iter_file)
423 extern void _IO_list_lock (void) __THROW;
424 libc_hidden_proto (_IO_list_lock)
425 extern void _IO_list_unlock (void) __THROW;
426 libc_hidden_proto (_IO_list_unlock)
427 extern void _IO_list_resetlock (void) __THROW;
428 libc_hidden_proto (_IO_list_resetlock)
430 /* Default jumptable functions. */
432 extern int _IO_default_underflow (_IO_FILE *) __THROW;
433 extern int _IO_default_uflow (_IO_FILE *);
434 libc_hidden_proto (_IO_default_uflow)
435 extern wint_t _IO_wdefault_uflow (_IO_FILE *);
436 libc_hidden_proto (_IO_wdefault_uflow)
437 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
438 libc_hidden_proto (_IO_default_doallocate)
439 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
440 libc_hidden_proto (_IO_wdefault_doallocate)
441 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
442 libc_hidden_proto (_IO_default_finish)
443 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
444 libc_hidden_proto (_IO_wdefault_finish)
445 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
446 libc_hidden_proto (_IO_default_pbackfail)
447 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
448 libc_hidden_proto (_IO_wdefault_pbackfail)
449 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
450 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
451 libc_hidden_proto (_IO_default_xsputn)
452 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
453 libc_hidden_proto (_IO_wdefault_xsputn)
454 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
455 libc_hidden_proto (_IO_default_xsgetn)
456 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
457 libc_hidden_proto (_IO_wdefault_xsgetn)
458 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
459 __THROW;
460 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
461 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
462 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
463 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
464 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
465 extern int _IO_default_sync (_IO_FILE *) __THROW;
466 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
467 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
468 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
470 extern const struct _IO_jump_t _IO_file_jumps;
471 libc_hidden_proto (_IO_file_jumps)
472 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
473 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
474 extern const struct _IO_jump_t _IO_wfile_jumps;
475 libc_hidden_proto (_IO_wfile_jumps)
476 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
477 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
478 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
479 extern const struct _IO_jump_t _IO_streambuf_jumps;
480 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
481 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
482 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
483 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
484 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
485 libc_hidden_proto (_IO_do_write)
486 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
487 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
488 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
489 libc_hidden_proto (_IO_wdo_write)
490 extern int _IO_flush_all_lockp (int);
491 extern int _IO_flush_all (void);
492 libc_hidden_proto (_IO_flush_all)
493 extern int _IO_cleanup (void);
494 extern void _IO_flush_all_linebuffered (void);
495 libc_hidden_proto (_IO_flush_all_linebuffered)
496 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
497 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
498 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
499 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
500 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
501 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
502 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
503 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
504 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
507 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
508 # define _IO_do_flush(_f) \
509 ((_f)->_mode <= 0 \
510 ? _IO_do_write(_f, (_f)->_IO_write_base, \
511 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
512 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
513 ((_f)->_wide_data->_IO_write_ptr \
514 - (_f)->_wide_data->_IO_write_base)))
515 #else
516 # define _IO_do_flush(_f) \
517 _IO_do_write(_f, (_f)->_IO_write_base, \
518 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
519 #endif
520 #define _IO_old_do_flush(_f) \
521 _IO_old_do_write(_f, (_f)->_IO_write_base, \
522 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
523 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
524 #define _IO_mask_flags(fp, f, mask) \
525 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
526 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
527 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
528 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
529 (fp)->_wide_data->_IO_read_ptr = (g), \
530 (fp)->_wide_data->_IO_read_end = (eg))
531 #define _IO_setp(__fp, __p, __ep) \
532 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
533 = __p, (__fp)->_IO_write_end = (__ep))
534 #define _IO_wsetp(__fp, __p, __ep) \
535 ((__fp)->_wide_data->_IO_write_base \
536 = (__fp)->_wide_data->_IO_write_ptr = __p, \
537 (__fp)->_wide_data->_IO_write_end = (__ep))
538 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
539 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
540 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
541 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
542 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
543 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
544 - (fp)->_wide_data->_IO_buf_base)
546 /* Jumptable functions for files. */
548 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
549 libc_hidden_proto (_IO_file_doallocate)
550 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
551 libc_hidden_proto (_IO_file_setbuf)
552 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
553 libc_hidden_proto (_IO_file_seekoff)
554 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
555 __THROW;
556 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
557 libc_hidden_proto (_IO_file_xsputn)
558 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
559 libc_hidden_proto (_IO_file_xsgetn)
560 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
561 libc_hidden_proto (_IO_file_stat)
562 extern int _IO_file_close (_IO_FILE *) __THROW;
563 libc_hidden_proto (_IO_file_close)
564 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
565 extern int _IO_file_underflow (_IO_FILE *);
566 libc_hidden_proto (_IO_file_underflow)
567 extern int _IO_file_underflow_mmap (_IO_FILE *);
568 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
569 extern int _IO_file_overflow (_IO_FILE *, int);
570 libc_hidden_proto (_IO_file_overflow)
571 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
572 extern void _IO_file_init (struct _IO_FILE_plus *) __THROW;
573 libc_hidden_proto (_IO_file_init)
574 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
575 libc_hidden_proto (_IO_file_attach)
576 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
577 libc_hidden_proto (_IO_file_open)
578 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
579 libc_hidden_proto (_IO_file_fopen)
580 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
581 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
582 libc_hidden_proto (_IO_file_read)
583 extern int _IO_file_sync (_IO_FILE *);
584 libc_hidden_proto (_IO_file_sync)
585 extern int _IO_file_close_it (_IO_FILE *);
586 libc_hidden_proto (_IO_file_close_it)
587 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
588 libc_hidden_proto (_IO_file_seek)
589 extern void _IO_file_finish (_IO_FILE *, int);
590 libc_hidden_proto (_IO_file_finish)
592 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
593 extern int _IO_new_file_close_it (_IO_FILE *);
594 extern void _IO_new_file_finish (_IO_FILE *, int);
595 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
596 int);
597 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
598 const struct _IO_jump_t *) __THROW;
599 extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW;
600 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
601 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
602 extern int _IO_new_file_sync (_IO_FILE *);
603 extern int _IO_new_file_underflow (_IO_FILE *);
604 extern int _IO_new_file_overflow (_IO_FILE *, int);
605 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
606 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
607 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
609 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
610 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
611 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
612 extern int _IO_old_file_underflow (_IO_FILE *);
613 extern int _IO_old_file_overflow (_IO_FILE *, int);
614 extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW;
615 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
616 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
617 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
618 extern int _IO_old_file_sync (_IO_FILE *);
619 extern int _IO_old_file_close_it (_IO_FILE *);
620 extern void _IO_old_file_finish (_IO_FILE *, int);
622 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
623 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
624 libc_hidden_proto (_IO_wfile_xsputn)
625 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
626 extern wint_t _IO_wfile_sync (_IO_FILE *);
627 libc_hidden_proto (_IO_wfile_sync)
628 extern wint_t _IO_wfile_underflow (_IO_FILE *);
629 libc_hidden_proto (_IO_wfile_underflow)
630 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
631 libc_hidden_proto (_IO_wfile_overflow)
632 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
633 libc_hidden_proto (_IO_wfile_seekoff)
635 /* Jumptable functions for proc_files. */
636 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
637 __THROW;
638 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
639 __THROW;
640 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
641 extern int _IO_proc_close (_IO_FILE *) __THROW;
642 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
643 extern int _IO_old_proc_close (_IO_FILE *);
645 /* Jumptable functions for strfiles. */
646 extern int _IO_str_underflow (_IO_FILE *) __THROW;
647 libc_hidden_proto (_IO_str_underflow)
648 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
649 libc_hidden_proto (_IO_str_overflow)
650 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
651 libc_hidden_proto (_IO_str_pbackfail)
652 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
653 libc_hidden_proto (_IO_str_seekoff)
654 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
656 /* Other strfile functions */
657 struct _IO_strfile_;
658 extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *)
659 __THROW;
660 extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int)
661 __THROW;
662 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
664 /* And the wide character versions. */
665 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
666 __THROW;
667 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
668 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
669 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
670 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
671 __THROW;
672 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
673 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
675 extern int _IO_vasprintf (char **result_ptr, const char *format,
676 _IO_va_list args) __THROW;
677 extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
678 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
679 const char *format, _IO_va_list args) __THROW;
682 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
683 libc_hidden_proto (_IO_getline)
684 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
685 int, int, int *);
686 libc_hidden_proto (_IO_getline_info)
687 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
688 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
689 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
690 wint_t, int, wint_t *);
692 extern struct _IO_FILE_plus *_IO_list_all;
693 libc_hidden_proto (_IO_list_all)
694 extern void (*_IO_cleanup_registration_needed) (void);
696 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
697 _IO_size_t, char *) __THROW;
698 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
699 attribute_hidden;
700 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
701 attribute_hidden;
703 #ifndef EOF
704 # define EOF (-1)
705 #endif
706 #ifndef NULL
707 # if defined __GNUG__ && \
708 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
709 # define NULL (__null)
710 # else
711 # if !defined(__cplusplus)
712 # define NULL ((void*)0)
713 # else
714 # define NULL (0)
715 # endif
716 # endif
717 #endif
719 #if _G_HAVE_MMAP
721 # include <unistd.h>
722 # include <fcntl.h>
723 # include <sys/mman.h>
724 # include <sys/param.h>
726 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
727 # define MAP_ANONYMOUS MAP_ANON
728 # endif
730 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
731 # undef _G_HAVE_MMAP
732 # define _G_HAVE_MMAP 0
733 # endif
735 #endif /* _G_HAVE_MMAP */
737 #if _G_HAVE_MMAP
739 # ifdef _LIBC
740 /* When using this code in the GNU libc we must not pollute the name space. */
741 # define mmap __mmap
742 # define munmap __munmap
743 # define ftruncate __ftruncate
744 # endif
746 # define ROUND_TO_PAGE(_S) \
747 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
749 # define FREE_BUF(_B, _S) \
750 munmap ((_B), ROUND_TO_PAGE (_S))
751 # define ALLOC_BUF(_B, _S, _R) \
752 do { \
753 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
754 PROT_READ | PROT_WRITE, \
755 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
756 if ((_B) == (char *) MAP_FAILED) \
757 return (_R); \
758 } while (0)
759 # define ALLOC_WBUF(_B, _S, _R) \
760 do { \
761 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
762 PROT_READ | PROT_WRITE, \
763 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
764 if ((_B) == (wchar_t *) MAP_FAILED) \
765 return (_R); \
766 } while (0)
768 #else /* _G_HAVE_MMAP */
770 # define FREE_BUF(_B, _S) \
771 free(_B)
772 # define ALLOC_BUF(_B, _S, _R) \
773 do { \
774 (_B) = (char*)malloc(_S); \
775 if ((_B) == NULL) \
776 return (_R); \
777 } while (0)
778 # define ALLOC_WBUF(_B, _S, _R) \
779 do { \
780 (_B) = (wchar_t *)malloc(_S); \
781 if ((_B) == NULL) \
782 return (_R); \
783 } while (0)
785 #endif /* _G_HAVE_MMAP */
787 #ifndef OS_FSTAT
788 # define OS_FSTAT fstat
789 #endif
790 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
792 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
793 #ifndef _IO_pos_BAD
794 # define _IO_pos_BAD ((_IO_off64_t) -1)
795 #endif
796 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
797 #ifndef _IO_pos_adjust
798 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
799 #endif
800 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
801 #ifndef _IO_pos_0
802 # define _IO_pos_0 ((_IO_off64_t) 0)
803 #endif
805 #ifdef __cplusplus
807 #endif
809 #ifdef _IO_MTSAFE_IO
810 /* check following! */
811 # ifdef _IO_USE_OLD_IO_FILE
812 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
813 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
815 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
816 # else
817 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
818 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
819 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
820 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
821 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
822 NULL, WDP, 0 }
823 # else
824 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
825 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
826 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
827 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
829 # endif
830 # endif
831 #else
832 # ifdef _IO_USE_OLD_IO_FILE
833 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
834 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
835 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
836 0, _IO_pos_BAD }
837 # else
838 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
839 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
840 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
841 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
842 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
843 NULL, WDP, 0 }
844 # else
845 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
846 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
847 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
848 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
850 # endif
851 # endif
852 #endif
854 #define _IO_va_start(args, last) va_start(args, last)
856 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
858 #if 1
859 # define COERCE_FILE(FILE) /* Nothing */
860 #else
861 /* This is part of the kludge for binary compatibility with old stdio. */
862 # define COERCE_FILE(FILE) \
863 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
864 && (FILE) = *(FILE**)&((int*)fp)[1])
865 #endif
867 #ifdef EINVAL
868 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
869 #else
870 # define MAYBE_SET_EINVAL /* nothing */
871 #endif
873 #ifdef IO_DEBUG
874 # define CHECK_FILE(FILE, RET) \
875 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
876 else { COERCE_FILE(FILE); \
877 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
878 { MAYBE_SET_EINVAL; return RET; }}
879 #else
880 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
881 #endif
883 static inline void
884 __attribute__ ((__always_inline__))
885 _IO_acquire_lock_fct (_IO_FILE **p)
887 _IO_FILE *fp = *p;
888 if ((fp->_flags & _IO_USER_LOCK) == 0)
889 _IO_funlockfile (fp);
892 static inline void
893 __attribute__ ((__always_inline__))
894 _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
896 _IO_FILE *fp = *p;
897 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
898 if ((fp->_flags & _IO_USER_LOCK) == 0)
899 _IO_funlockfile (fp);
902 #if !defined _IO_MTSAFE_IO && !defined NOT_IN_libc
903 # define _IO_acquire_lock(_fp) \
904 do { \
905 _IO_FILE *_IO_acquire_lock_file = NULL
906 # define _IO_acquire_lock_clear_flags2(_fp) \
907 do { \
908 _IO_FILE *_IO_acquire_lock_file = (_fp)
909 # define _IO_release_lock(_fp) \
910 if (_IO_acquire_lock_file != NULL) \
911 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
912 | _IO_FLAGS2_SCANF_STD); \
913 } while (0)
914 #endif