Consolidate non cancellable writev call
[glibc.git] / libio / libioP.h
blob1832b44cc7f009aa9e72af6e3a6365e49d747a38
1 /* Copyright (C) 1993-2017 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 <stddef.h>
37 #include <errno.h>
38 #ifndef __set_errno
39 # define __set_errno(Val) errno = (Val)
40 #endif
41 #if defined __GLIBC__ && __GLIBC__ >= 2
42 # include <libc-lock.h>
43 #else
44 /*# include <comthread.h>*/
45 #endif
47 #include <math_ldbl_opt.h>
49 #include "iolibio.h"
51 /* Control of exported symbols. Used in glibc. By default we don't
52 do anything. */
53 #ifndef libc_hidden_proto
54 # define libc_hidden_proto(name)
55 #endif
56 #ifndef libc_hidden_def
57 # define libc_hidden_def(name)
58 #endif
59 #ifndef libc_hidden_weak
60 # define libc_hidden_weak(name)
61 #endif
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
67 #define _IO_seek_set 0
68 #define _IO_seek_cur 1
69 #define _IO_seek_end 2
71 /* THE JUMPTABLE FUNCTIONS.
73 * The _IO_FILE type is used to implement the FILE type in GNU libc,
74 * as well as the streambuf class in GNU iostreams for C++.
75 * These are all the same, just used differently.
76 * An _IO_FILE (or FILE) object is allows followed by a pointer to
77 * a jump table (of pointers to functions). The pointer is accessed
78 * with the _IO_JUMPS macro. The jump table has an eccentric format,
79 * so as to be compatible with the layout of a C++ virtual function table.
80 * (as implemented by g++). When a pointer to a streambuf object is
81 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
82 * happens to point to the virtual function table of the streambuf.
83 * Thus the _IO_JUMPS function table used for C stdio/libio does
84 * double duty as the virtual function table for C++ streambuf.
86 * The entries in the _IO_JUMPS function table (and hence also the
87 * virtual functions of a streambuf) are described below.
88 * The first parameter of each function entry is the _IO_FILE/streambuf
89 * object being acted on (i.e. the 'this' parameter).
92 #ifdef _LIBC
93 # include <shlib-compat.h>
94 # if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
95 /* Setting this macro disables the use of the _vtable_offset
96 bias in _IO_JUMPS_FUNCS, below. That is only needed if we
97 want to support old binaries (see oldfileops.c). */
98 # define _G_IO_NO_BACKWARD_COMPAT 1
99 # endif
100 #endif
102 #if (!defined _IO_USE_OLD_IO_FILE \
103 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
104 # define _IO_JUMPS_OFFSET 1
105 #else
106 # define _IO_JUMPS_OFFSET 0
107 #endif
109 /* Type of MEMBER in struct type TYPE. */
110 #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
112 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
113 violation in case THIS has a different pointer type. */
114 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
115 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
116 + offsetof(TYPE, MEMBER)))
118 #define _IO_JUMPS(THIS) (THIS)->vtable
119 #define _IO_JUMPS_FILE_plus(THIS) \
120 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
121 #define _IO_WIDE_JUMPS(THIS) \
122 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
123 #define _IO_CHECK_WIDE(THIS) \
124 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
126 #if _IO_JUMPS_OFFSET
127 # define _IO_JUMPS_FUNC(THIS) \
128 (IO_validate_vtable \
129 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
130 + (THIS)->_vtable_offset)))
131 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
132 #else
133 # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
134 # define _IO_vtable_offset(THIS) 0
135 #endif
136 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
137 #define JUMP_FIELD(TYPE, NAME) TYPE NAME
138 #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
139 #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
140 #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
141 #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
142 #define JUMP_INIT(NAME, VALUE) VALUE
143 #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
145 #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
146 #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
147 #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
148 #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
150 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
151 It does not delete (free) it, but does everything else to finalize it.
152 It matches the streambuf::~streambuf virtual destructor. */
153 typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
154 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
155 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
157 /* The 'overflow' hook flushes the buffer.
158 The second argument is a character, or EOF.
159 It matches the streambuf::overflow virtual function. */
160 typedef int (*_IO_overflow_t) (_IO_FILE *, int);
161 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
162 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
164 /* The 'underflow' hook tries to fills the get buffer.
165 It returns the next character (as an unsigned char) or EOF. The next
166 character remains in the get buffer, and the get position is not changed.
167 It matches the streambuf::underflow virtual function. */
168 typedef int (*_IO_underflow_t) (_IO_FILE *);
169 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
170 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
172 /* The 'uflow' hook returns the next character in the input stream
173 (cast to unsigned char), and increments the read position;
174 EOF is returned on failure.
175 It matches the streambuf::uflow virtual function, which is not in the
176 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
177 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
178 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
180 /* The 'pbackfail' hook handles backing up.
181 It matches the streambuf::pbackfail virtual function. */
182 typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
183 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
184 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
186 /* The 'xsputn' hook writes upto N characters from buffer DATA.
187 Returns EOF or the number of character actually written.
188 It matches the streambuf::xsputn virtual function. */
189 typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
190 _IO_size_t N);
191 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
192 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
194 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
195 Returns the number of character actually read.
196 It matches the streambuf::xsgetn virtual function. */
197 typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
198 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
199 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
201 /* The 'seekoff' hook moves the stream position to a new position
202 relative to the start of the file (if DIR==0), the current position
203 (MODE==1), or the end of the file (MODE==2).
204 It matches the streambuf::seekoff virtual function.
205 It is also used for the ANSI fseek function. */
206 typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
207 int MODE);
208 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
209 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
211 /* The 'seekpos' hook also moves the stream position,
212 but to an absolute position given by a fpos64_t (seekpos).
213 It matches the streambuf::seekpos virtual function.
214 It is also used for the ANSI fgetpos and fsetpos functions. */
215 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
216 typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
217 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
218 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
220 /* The 'setbuf' hook gives a buffer to the file.
221 It matches the streambuf::setbuf virtual function. */
222 typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
223 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
224 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
226 /* The 'sync' hook attempts to synchronize the internal data structures
227 of the file with the external state.
228 It matches the streambuf::sync virtual function. */
229 typedef int (*_IO_sync_t) (_IO_FILE *);
230 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
231 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
233 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
234 It matches the streambuf::doallocate virtual function, which is not
235 in the ANSI/ISO C++ standard, but is part traditional implementations. */
236 typedef int (*_IO_doallocate_t) (_IO_FILE *);
237 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
238 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
240 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
241 sysstat) are low-level hooks specific to this implementation.
242 There is no correspondence in the ANSI/ISO C++ standard library.
243 The hooks basically correspond to the Unix system functions
244 (read, write, close, lseek, and stat) except that a _IO_FILE*
245 parameter is used instead of an integer file descriptor; the default
246 implementation used for normal files just calls those functions.
247 The advantage of overriding these functions instead of the higher-level
248 ones (underflow, overflow etc) is that you can leave all the buffering
249 higher-level functions. */
251 /* The 'sysread' hook is used to read data from the external file into
252 an existing buffer. It generalizes the Unix read(2) function.
253 It matches the streambuf::sys_read virtual function, which is
254 specific to this implementation. */
255 typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
256 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
257 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
259 /* The 'syswrite' hook is used to write data from an existing buffer
260 to an external file. It generalizes the Unix write(2) function.
261 It matches the streambuf::sys_write virtual function, which is
262 specific to this implementation. */
263 typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
264 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
265 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
267 /* The 'sysseek' hook is used to re-position an external file.
268 It generalizes the Unix lseek(2) function.
269 It matches the streambuf::sys_seek virtual function, which is
270 specific to this implementation. */
271 typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
272 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
273 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
275 /* The 'sysclose' hook is used to finalize (close, finish up) an
276 external file. It generalizes the Unix close(2) function.
277 It matches the streambuf::sys_close virtual function, which is
278 specific to this implementation. */
279 typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
280 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
281 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
283 /* The 'sysstat' hook is used to get information about an external file
284 into a struct stat buffer. It generalizes the Unix fstat(2) call.
285 It matches the streambuf::sys_stat virtual function, which is
286 specific to this implementation. */
287 typedef int (*_IO_stat_t) (_IO_FILE *, void *);
288 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
289 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
291 /* The 'showmany' hook can be used to get an image how much input is
292 available. In many cases the answer will be 0 which means unknown
293 but some cases one can provide real information. */
294 typedef int (*_IO_showmanyc_t) (_IO_FILE *);
295 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
296 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
298 /* The 'imbue' hook is used to get information about the currently
299 installed locales. */
300 typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
301 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
302 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
305 #define _IO_CHAR_TYPE char /* unsigned char ? */
306 #define _IO_INT_TYPE int
308 struct _IO_jump_t
310 JUMP_FIELD(size_t, __dummy);
311 JUMP_FIELD(size_t, __dummy2);
312 JUMP_FIELD(_IO_finish_t, __finish);
313 JUMP_FIELD(_IO_overflow_t, __overflow);
314 JUMP_FIELD(_IO_underflow_t, __underflow);
315 JUMP_FIELD(_IO_underflow_t, __uflow);
316 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
317 /* showmany */
318 JUMP_FIELD(_IO_xsputn_t, __xsputn);
319 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
320 JUMP_FIELD(_IO_seekoff_t, __seekoff);
321 JUMP_FIELD(_IO_seekpos_t, __seekpos);
322 JUMP_FIELD(_IO_setbuf_t, __setbuf);
323 JUMP_FIELD(_IO_sync_t, __sync);
324 JUMP_FIELD(_IO_doallocate_t, __doallocate);
325 JUMP_FIELD(_IO_read_t, __read);
326 JUMP_FIELD(_IO_write_t, __write);
327 JUMP_FIELD(_IO_seek_t, __seek);
328 JUMP_FIELD(_IO_close_t, __close);
329 JUMP_FIELD(_IO_stat_t, __stat);
330 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
331 JUMP_FIELD(_IO_imbue_t, __imbue);
332 #if 0
333 get_column;
334 set_column;
335 #endif
338 /* We always allocate an extra word following an _IO_FILE.
339 This contains a pointer to the function jump table used.
340 This is for compatibility with C++ streambuf; the word can
341 be used to smash to a pointer to a virtual function table. */
343 struct _IO_FILE_plus
345 _IO_FILE file;
346 const struct _IO_jump_t *vtable;
349 #ifdef _IO_USE_OLD_IO_FILE
350 /* This structure is used by the compatibility code as if it were an
351 _IO_FILE_plus, but has enough space to initialize the _mode argument
352 of an _IO_FILE_complete. */
353 struct _IO_FILE_complete_plus
355 struct _IO_FILE_complete file;
356 const struct _IO_jump_t *vtable;
358 #endif
360 /* Special file type for fopencookie function. */
361 struct _IO_cookie_file
363 struct _IO_FILE_plus __fp;
364 void *__cookie;
365 _IO_cookie_io_functions_t __io_functions;
368 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
369 _IO_cookie_io_functions_t io_functions);
372 /* Iterator type for walking global linked list of _IO_FILE objects. */
374 typedef struct _IO_FILE *_IO_ITER;
376 /* Generic functions */
378 extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
379 extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
380 extern int _IO_switch_to_get_mode (_IO_FILE *);
381 libc_hidden_proto (_IO_switch_to_get_mode)
382 extern void _IO_init_internal (_IO_FILE *, int) attribute_hidden;
383 extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
384 libc_hidden_proto (_IO_sputbackc)
385 extern int _IO_sungetc (_IO_FILE *) __THROW;
386 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
387 libc_hidden_proto (_IO_un_link)
388 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
389 libc_hidden_proto (_IO_link_in)
390 extern void _IO_doallocbuf (_IO_FILE *) __THROW;
391 libc_hidden_proto (_IO_doallocbuf)
392 extern void _IO_unsave_markers (_IO_FILE *) __THROW;
393 libc_hidden_proto (_IO_unsave_markers)
394 extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
395 libc_hidden_proto (_IO_setb)
396 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
397 libc_hidden_proto (_IO_adjust_column)
398 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
400 _IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
401 libc_hidden_proto (_IO_least_wmarker)
402 extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
403 libc_hidden_proto (_IO_switch_to_main_wget_area)
404 extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
405 libc_hidden_proto (_IO_switch_to_wbackup_area)
406 extern int _IO_switch_to_wget_mode (_IO_FILE *);
407 libc_hidden_proto (_IO_switch_to_wget_mode)
408 extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
409 libc_hidden_proto (_IO_wsetb)
410 extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
411 libc_hidden_proto (_IO_sputbackwc)
412 extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
413 extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
414 libc_hidden_proto (_IO_wdoallocbuf)
415 extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
416 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
417 extern _IO_off64_t get_file_offset (_IO_FILE *fp);
419 /* Marker-related function. */
421 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
422 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
423 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
424 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
425 __THROW;
426 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
427 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
428 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
429 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
431 /* Functions for iterating global list and dealing with its lock */
433 extern _IO_ITER _IO_iter_begin (void) __THROW;
434 libc_hidden_proto (_IO_iter_begin)
435 extern _IO_ITER _IO_iter_end (void) __THROW;
436 libc_hidden_proto (_IO_iter_end)
437 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
438 libc_hidden_proto (_IO_iter_next)
439 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
440 libc_hidden_proto (_IO_iter_file)
441 extern void _IO_list_lock (void) __THROW;
442 libc_hidden_proto (_IO_list_lock)
443 extern void _IO_list_unlock (void) __THROW;
444 libc_hidden_proto (_IO_list_unlock)
445 extern void _IO_list_resetlock (void) __THROW;
446 libc_hidden_proto (_IO_list_resetlock)
447 extern void _IO_enable_locks (void) __THROW;
448 libc_hidden_proto (_IO_enable_locks)
450 /* Default jumptable functions. */
452 extern int _IO_default_underflow (_IO_FILE *) __THROW;
453 extern int _IO_default_uflow (_IO_FILE *);
454 libc_hidden_proto (_IO_default_uflow)
455 extern wint_t _IO_wdefault_uflow (_IO_FILE *);
456 libc_hidden_proto (_IO_wdefault_uflow)
457 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
458 libc_hidden_proto (_IO_default_doallocate)
459 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
460 libc_hidden_proto (_IO_wdefault_doallocate)
461 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
462 libc_hidden_proto (_IO_default_finish)
463 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
464 libc_hidden_proto (_IO_wdefault_finish)
465 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
466 libc_hidden_proto (_IO_default_pbackfail)
467 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
468 libc_hidden_proto (_IO_wdefault_pbackfail)
469 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
470 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
471 libc_hidden_proto (_IO_default_xsputn)
472 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
473 libc_hidden_proto (_IO_wdefault_xsputn)
474 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
475 libc_hidden_proto (_IO_default_xsgetn)
476 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
477 libc_hidden_proto (_IO_wdefault_xsgetn)
478 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
479 __THROW;
480 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
481 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
482 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
483 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
484 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
485 extern int _IO_default_sync (_IO_FILE *) __THROW;
486 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
487 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
488 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
490 extern const struct _IO_jump_t _IO_file_jumps;
491 libc_hidden_proto (_IO_file_jumps)
492 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
493 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
494 extern const struct _IO_jump_t _IO_wfile_jumps;
495 libc_hidden_proto (_IO_wfile_jumps)
496 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
497 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
498 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
499 extern const struct _IO_jump_t _IO_streambuf_jumps;
500 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
501 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
502 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
503 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
504 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
505 libc_hidden_proto (_IO_do_write)
506 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
507 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
508 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
509 libc_hidden_proto (_IO_wdo_write)
510 extern int _IO_flush_all_lockp (int);
511 extern int _IO_flush_all (void);
512 libc_hidden_proto (_IO_flush_all)
513 extern int _IO_cleanup (void);
514 extern void _IO_flush_all_linebuffered (void);
515 libc_hidden_proto (_IO_flush_all_linebuffered)
516 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
517 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
518 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
519 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
520 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
521 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
522 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
523 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
524 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
527 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
528 # define _IO_do_flush(_f) \
529 ((_f)->_mode <= 0 \
530 ? _IO_do_write(_f, (_f)->_IO_write_base, \
531 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
532 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
533 ((_f)->_wide_data->_IO_write_ptr \
534 - (_f)->_wide_data->_IO_write_base)))
535 #else
536 # define _IO_do_flush(_f) \
537 _IO_do_write(_f, (_f)->_IO_write_base, \
538 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
539 #endif
540 #define _IO_old_do_flush(_f) \
541 _IO_old_do_write(_f, (_f)->_IO_write_base, \
542 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
543 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
544 #define _IO_mask_flags(fp, f, mask) \
545 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
546 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
547 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
548 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
549 (fp)->_wide_data->_IO_read_ptr = (g), \
550 (fp)->_wide_data->_IO_read_end = (eg))
551 #define _IO_setp(__fp, __p, __ep) \
552 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
553 = __p, (__fp)->_IO_write_end = (__ep))
554 #define _IO_wsetp(__fp, __p, __ep) \
555 ((__fp)->_wide_data->_IO_write_base \
556 = (__fp)->_wide_data->_IO_write_ptr = __p, \
557 (__fp)->_wide_data->_IO_write_end = (__ep))
558 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
559 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
560 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
561 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
562 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
563 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
564 - (fp)->_wide_data->_IO_buf_base)
566 /* Jumptable functions for files. */
568 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
569 libc_hidden_proto (_IO_file_doallocate)
570 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
571 libc_hidden_proto (_IO_file_setbuf)
572 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
573 libc_hidden_proto (_IO_file_seekoff)
574 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
575 __THROW;
576 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
577 libc_hidden_proto (_IO_file_xsputn)
578 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
579 libc_hidden_proto (_IO_file_xsgetn)
580 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
581 libc_hidden_proto (_IO_file_stat)
582 extern int _IO_file_close (_IO_FILE *) __THROW;
583 libc_hidden_proto (_IO_file_close)
584 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
585 extern int _IO_file_underflow (_IO_FILE *);
586 libc_hidden_proto (_IO_file_underflow)
587 extern int _IO_file_underflow_mmap (_IO_FILE *);
588 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
589 extern int _IO_file_overflow (_IO_FILE *, int);
590 libc_hidden_proto (_IO_file_overflow)
591 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
592 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
593 libc_hidden_proto (_IO_file_attach)
594 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
595 libc_hidden_proto (_IO_file_open)
596 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
597 libc_hidden_proto (_IO_file_fopen)
598 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
599 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
600 libc_hidden_proto (_IO_file_read)
601 extern int _IO_file_sync (_IO_FILE *);
602 libc_hidden_proto (_IO_file_sync)
603 extern int _IO_file_close_it (_IO_FILE *);
604 libc_hidden_proto (_IO_file_close_it)
605 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
606 libc_hidden_proto (_IO_file_seek)
607 extern void _IO_file_finish (_IO_FILE *, int);
608 libc_hidden_proto (_IO_file_finish)
610 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
611 extern int _IO_new_file_close_it (_IO_FILE *);
612 extern void _IO_new_file_finish (_IO_FILE *, int);
613 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
614 int);
615 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
616 const struct _IO_jump_t *) __THROW;
617 extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
618 __THROW attribute_hidden;
619 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
620 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
621 extern int _IO_new_file_sync (_IO_FILE *);
622 extern int _IO_new_file_underflow (_IO_FILE *);
623 extern int _IO_new_file_overflow (_IO_FILE *, int);
624 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
625 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
626 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
628 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
629 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
630 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
631 extern int _IO_old_file_underflow (_IO_FILE *);
632 extern int _IO_old_file_overflow (_IO_FILE *, int);
633 extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
634 __THROW attribute_hidden;
635 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
636 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
637 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
638 extern int _IO_old_file_sync (_IO_FILE *);
639 extern int _IO_old_file_close_it (_IO_FILE *);
640 extern void _IO_old_file_finish (_IO_FILE *, int);
642 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
643 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
644 libc_hidden_proto (_IO_wfile_xsputn)
645 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
646 extern wint_t _IO_wfile_sync (_IO_FILE *);
647 libc_hidden_proto (_IO_wfile_sync)
648 extern wint_t _IO_wfile_underflow (_IO_FILE *);
649 libc_hidden_proto (_IO_wfile_underflow)
650 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
651 libc_hidden_proto (_IO_wfile_overflow)
652 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
653 libc_hidden_proto (_IO_wfile_seekoff)
655 /* Jumptable functions for proc_files. */
656 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
657 __THROW;
658 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
659 __THROW;
660 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
661 extern int _IO_proc_close (_IO_FILE *) __THROW;
662 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
663 extern int _IO_old_proc_close (_IO_FILE *);
665 /* Jumptable functions for strfiles. */
666 extern int _IO_str_underflow (_IO_FILE *) __THROW;
667 libc_hidden_proto (_IO_str_underflow)
668 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
669 libc_hidden_proto (_IO_str_overflow)
670 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
671 libc_hidden_proto (_IO_str_pbackfail)
672 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
673 libc_hidden_proto (_IO_str_seekoff)
674 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
676 /* Other strfile functions */
677 struct _IO_strfile_;
678 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
680 /* And the wide character versions. */
681 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
682 __THROW;
683 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
684 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
685 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
686 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
687 __THROW;
688 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
689 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
691 extern int _IO_vasprintf (char **result_ptr, const char *format,
692 _IO_va_list args) __THROW;
693 extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
694 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
695 const char *format, _IO_va_list args) __THROW;
698 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
699 libc_hidden_proto (_IO_getline)
700 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
701 int, int, int *);
702 libc_hidden_proto (_IO_getline_info)
703 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
704 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
705 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
706 wint_t, int, wint_t *);
708 extern struct _IO_FILE_plus *_IO_list_all;
709 libc_hidden_proto (_IO_list_all)
710 extern void (*_IO_cleanup_registration_needed) (void);
712 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
713 _IO_size_t, char *) __THROW;
714 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
715 attribute_hidden;
716 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
717 attribute_hidden;
719 #ifndef EOF
720 # define EOF (-1)
721 #endif
722 #ifndef NULL
723 # if defined __GNUG__ && \
724 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
725 # define NULL (__null)
726 # else
727 # if !defined(__cplusplus)
728 # define NULL ((void*)0)
729 # else
730 # define NULL (0)
731 # endif
732 # endif
733 #endif
735 #if _G_HAVE_MMAP
737 # include <unistd.h>
738 # include <fcntl.h>
739 # include <sys/mman.h>
740 # include <sys/param.h>
742 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
743 # define MAP_ANONYMOUS MAP_ANON
744 # endif
746 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
747 # undef _G_HAVE_MMAP
748 # define _G_HAVE_MMAP 0
749 # endif
751 #endif /* _G_HAVE_MMAP */
753 #if _G_HAVE_MMAP
755 # ifdef _LIBC
756 /* When using this code in the GNU libc we must not pollute the name space. */
757 # define mmap __mmap
758 # define munmap __munmap
759 # define ftruncate __ftruncate
760 # endif
761 #endif /* _G_HAVE_MMAP */
763 #ifndef OS_FSTAT
764 # define OS_FSTAT fstat
765 #endif
766 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
768 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
769 #ifndef _IO_pos_BAD
770 # define _IO_pos_BAD ((_IO_off64_t) -1)
771 #endif
772 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
773 #ifndef _IO_pos_adjust
774 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
775 #endif
776 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
777 #ifndef _IO_pos_0
778 # define _IO_pos_0 ((_IO_off64_t) 0)
779 #endif
781 #ifdef __cplusplus
783 #endif
785 #ifdef _IO_MTSAFE_IO
786 /* check following! */
787 # ifdef _IO_USE_OLD_IO_FILE
788 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
789 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
790 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
791 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
792 # else
793 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
794 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
795 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
796 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
797 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
798 NULL, WDP, 0 }
799 # else
800 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
801 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
802 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
803 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
805 # endif
806 # endif
807 #else
808 # ifdef _IO_USE_OLD_IO_FILE
809 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
810 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
811 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
812 0, _IO_pos_BAD }
813 # else
814 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
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 }, 0, _IO_pos_BAD, \
819 NULL, WDP, 0 }
820 # else
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 }, 0, _IO_pos_BAD, \
826 # endif
827 # endif
828 #endif
830 #define _IO_va_start(args, last) va_start(args, last)
832 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
834 #if 1
835 # define COERCE_FILE(FILE) /* Nothing */
836 #else
837 /* This is part of the kludge for binary compatibility with old stdio. */
838 # define COERCE_FILE(FILE) \
839 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
840 && (FILE) = *(FILE**)&((int*)fp)[1])
841 #endif
843 #ifdef EINVAL
844 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
845 #else
846 # define MAYBE_SET_EINVAL /* nothing */
847 #endif
849 #ifdef IO_DEBUG
850 # define CHECK_FILE(FILE, RET) \
851 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
852 else { COERCE_FILE(FILE); \
853 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
854 { MAYBE_SET_EINVAL; return RET; }}
855 #else
856 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
857 #endif
859 static inline void
860 __attribute__ ((__always_inline__))
861 _IO_acquire_lock_fct (_IO_FILE **p)
863 _IO_FILE *fp = *p;
864 if ((fp->_flags & _IO_USER_LOCK) == 0)
865 _IO_funlockfile (fp);
868 static inline void
869 __attribute__ ((__always_inline__))
870 _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
872 _IO_FILE *fp = *p;
873 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
874 if ((fp->_flags & _IO_USER_LOCK) == 0)
875 _IO_funlockfile (fp);
878 #if !defined _IO_MTSAFE_IO && IS_IN (libc)
879 # define _IO_acquire_lock(_fp) \
880 do { \
881 _IO_FILE *_IO_acquire_lock_file = NULL
882 # define _IO_acquire_lock_clear_flags2(_fp) \
883 do { \
884 _IO_FILE *_IO_acquire_lock_file = (_fp)
885 # define _IO_release_lock(_fp) \
886 if (_IO_acquire_lock_file != NULL) \
887 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
888 | _IO_FLAGS2_SCANF_STD); \
889 } while (0)
890 #endif
892 /* Collect all vtables in a special section for vtable verification.
893 These symbols cover the extent of this section. */
894 symbol_set_declare (__libc_IO_vtables)
896 /* libio vtables need to carry this attribute so that they pass
897 validation. */
898 #define libio_vtable __attribute__ ((section ("__libc_IO_vtables")))
900 #ifdef SHARED
901 /* If equal to &_IO_vtable_check (with pointer guard protection),
902 unknown vtable pointers are valid. This function pointer is solely
903 used as a flag. */
904 extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
906 /* Assigns the passed function pointer (either NULL or
907 &_IO_vtable_check) to IO_accept_foreign_vtables. */
908 static inline void
909 IO_set_accept_foreign_vtables (void (*flag) (void))
911 #ifdef PTR_MANGLE
912 PTR_MANGLE (flag);
913 #endif
914 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
917 #else /* !SHARED */
919 /* The statically-linked version does nothing. */
920 static inline void
921 IO_set_accept_foreign_vtables (void (*flag) (void))
925 #endif
927 /* Check if unknown vtable pointers are permitted; otherwise,
928 terminate the process. */
929 void _IO_vtable_check (void) attribute_hidden;
931 /* Perform vtable pointer validation. If validation fails, terminate
932 the process. */
933 static inline const struct _IO_jump_t *
934 IO_validate_vtable (const struct _IO_jump_t *vtable)
936 /* Fast path: The vtable pointer is within the __libc_IO_vtables
937 section. */
938 uintptr_t section_length = __stop___libc_IO_vtables - __start___libc_IO_vtables;
939 const char *ptr = (const char *) vtable;
940 uintptr_t offset = ptr - __start___libc_IO_vtables;
941 if (__glibc_unlikely (offset >= section_length))
942 /* The vtable pointer is not in the expected section. Use the
943 slow path, which will terminate the process if necessary. */
944 _IO_vtable_check ();
945 return vtable;