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