Remove unused math/Makefile variable libm-test-incs.
[glibc.git] / libio / libioP.h
blob58cc9de094b2d9f9a5aa90170ac5faea363f0bbf
1 /* Copyright (C) 1993-2018 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 #ifndef _LIBIOP_H
36 #define _LIBIOP_H 1
38 #include <stddef.h>
40 #include <errno.h>
41 #include <libc-lock.h>
43 #include <math_ldbl_opt.h>
45 #include <stdio.h>
46 #include <libio/libio.h>
47 #include "iolibio.h"
49 #include <shlib-compat.h>
51 /* For historical reasons this is the name of the sysdeps header that
52 adjusts the libio configuration. */
53 #include <_G_config.h>
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
59 #define _IO_seek_set 0
60 #define _IO_seek_cur 1
61 #define _IO_seek_end 2
63 /* THE JUMPTABLE FUNCTIONS.
65 * The _IO_FILE type is used to implement the FILE type in GNU libc,
66 * as well as the streambuf class in GNU iostreams for C++.
67 * These are all the same, just used differently.
68 * An _IO_FILE (or FILE) object is allows followed by a pointer to
69 * a jump table (of pointers to functions). The pointer is accessed
70 * with the _IO_JUMPS macro. The jump table has an eccentric format,
71 * so as to be compatible with the layout of a C++ virtual function table.
72 * (as implemented by g++). When a pointer to a streambuf object is
73 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
74 * happens to point to the virtual function table of the streambuf.
75 * Thus the _IO_JUMPS function table used for C stdio/libio does
76 * double duty as the virtual function table for C++ streambuf.
78 * The entries in the _IO_JUMPS function table (and hence also the
79 * virtual functions of a streambuf) are described below.
80 * The first parameter of each function entry is the _IO_FILE/streambuf
81 * object being acted on (i.e. the 'this' parameter).
84 /* Setting this macro to 1 enables the use of the _vtable_offset bias
85 in _IO_JUMPS_FUNCS, below. This is only needed for new-format
86 _IO_FILE in libc that must support old binaries (see oldfileops.c). */
87 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) && !defined _IO_USE_OLD_IO_FILE
88 # define _IO_JUMPS_OFFSET 1
89 #else
90 # define _IO_JUMPS_OFFSET 0
91 #endif
93 /* Type of MEMBER in struct type TYPE. */
94 #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
96 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
97 violation in case THIS has a different pointer type. */
98 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
99 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
100 + offsetof(TYPE, MEMBER)))
102 #define _IO_JUMPS(THIS) (THIS)->vtable
103 #define _IO_JUMPS_FILE_plus(THIS) \
104 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
105 #define _IO_WIDE_JUMPS(THIS) \
106 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
107 #define _IO_CHECK_WIDE(THIS) \
108 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
110 #if _IO_JUMPS_OFFSET
111 # define _IO_JUMPS_FUNC(THIS) \
112 (IO_validate_vtable \
113 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_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_validate_vtable (_IO_JUMPS_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_internal (_IO_FILE *, int) attribute_hidden;
367 extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
368 libc_hidden_proto (_IO_sputbackc)
369 extern int _IO_sungetc (_IO_FILE *) __THROW;
370 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
371 libc_hidden_proto (_IO_un_link)
372 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
373 libc_hidden_proto (_IO_link_in)
374 extern void _IO_doallocbuf (_IO_FILE *) __THROW;
375 libc_hidden_proto (_IO_doallocbuf)
376 extern void _IO_unsave_markers (_IO_FILE *) __THROW;
377 libc_hidden_proto (_IO_unsave_markers)
378 extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
379 libc_hidden_proto (_IO_setb)
380 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
381 libc_hidden_proto (_IO_adjust_column)
382 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
384 _IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
385 libc_hidden_proto (_IO_least_wmarker)
386 extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
387 libc_hidden_proto (_IO_switch_to_main_wget_area)
388 extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
389 libc_hidden_proto (_IO_switch_to_wbackup_area)
390 extern int _IO_switch_to_wget_mode (_IO_FILE *);
391 libc_hidden_proto (_IO_switch_to_wget_mode)
392 extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
393 libc_hidden_proto (_IO_wsetb)
394 extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
395 libc_hidden_proto (_IO_sputbackwc)
396 extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
397 extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
398 libc_hidden_proto (_IO_wdoallocbuf)
399 extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
400 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
401 extern _IO_off64_t get_file_offset (_IO_FILE *fp);
403 /* Marker-related function. */
405 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
406 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
407 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
408 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
409 __THROW;
410 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
411 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
412 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
413 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
415 /* Functions for iterating global list and dealing with its lock */
417 extern _IO_ITER _IO_iter_begin (void) __THROW;
418 libc_hidden_proto (_IO_iter_begin)
419 extern _IO_ITER _IO_iter_end (void) __THROW;
420 libc_hidden_proto (_IO_iter_end)
421 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
422 libc_hidden_proto (_IO_iter_next)
423 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
424 libc_hidden_proto (_IO_iter_file)
425 extern void _IO_list_lock (void) __THROW;
426 libc_hidden_proto (_IO_list_lock)
427 extern void _IO_list_unlock (void) __THROW;
428 libc_hidden_proto (_IO_list_unlock)
429 extern void _IO_list_resetlock (void) __THROW;
430 libc_hidden_proto (_IO_list_resetlock)
431 extern void _IO_enable_locks (void) __THROW;
432 libc_hidden_proto (_IO_enable_locks)
434 /* Default jumptable functions. */
436 extern int _IO_default_underflow (_IO_FILE *) __THROW;
437 extern int _IO_default_uflow (_IO_FILE *);
438 libc_hidden_proto (_IO_default_uflow)
439 extern wint_t _IO_wdefault_uflow (_IO_FILE *);
440 libc_hidden_proto (_IO_wdefault_uflow)
441 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
442 libc_hidden_proto (_IO_default_doallocate)
443 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
444 libc_hidden_proto (_IO_wdefault_doallocate)
445 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
446 libc_hidden_proto (_IO_default_finish)
447 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
448 libc_hidden_proto (_IO_wdefault_finish)
449 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
450 libc_hidden_proto (_IO_default_pbackfail)
451 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
452 libc_hidden_proto (_IO_wdefault_pbackfail)
453 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
454 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
455 libc_hidden_proto (_IO_default_xsputn)
456 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
457 libc_hidden_proto (_IO_wdefault_xsputn)
458 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
459 libc_hidden_proto (_IO_default_xsgetn)
460 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
461 libc_hidden_proto (_IO_wdefault_xsgetn)
462 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
463 __THROW;
464 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
465 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
466 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
467 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
468 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
469 extern int _IO_default_sync (_IO_FILE *) __THROW;
470 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
471 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
472 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
474 extern const struct _IO_jump_t _IO_file_jumps;
475 libc_hidden_proto (_IO_file_jumps)
476 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
477 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
478 extern const struct _IO_jump_t _IO_wfile_jumps;
479 libc_hidden_proto (_IO_wfile_jumps)
480 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
481 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
482 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
483 extern const struct _IO_jump_t _IO_streambuf_jumps;
484 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
485 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
486 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
487 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
488 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
489 libc_hidden_proto (_IO_do_write)
490 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
491 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
492 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
493 libc_hidden_proto (_IO_wdo_write)
494 extern int _IO_flush_all_lockp (int);
495 extern int _IO_flush_all (void);
496 libc_hidden_proto (_IO_flush_all)
497 extern int _IO_cleanup (void);
498 extern void _IO_flush_all_linebuffered (void);
499 libc_hidden_proto (_IO_flush_all_linebuffered)
500 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
501 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
502 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
503 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
504 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
505 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
506 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
507 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
508 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
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 #define _IO_old_do_flush(_f) \
519 _IO_old_do_write(_f, (_f)->_IO_write_base, \
520 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
521 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
522 #define _IO_mask_flags(fp, f, mask) \
523 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
524 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
525 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
526 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
527 (fp)->_wide_data->_IO_read_ptr = (g), \
528 (fp)->_wide_data->_IO_read_end = (eg))
529 #define _IO_setp(__fp, __p, __ep) \
530 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
531 = __p, (__fp)->_IO_write_end = (__ep))
532 #define _IO_wsetp(__fp, __p, __ep) \
533 ((__fp)->_wide_data->_IO_write_base \
534 = (__fp)->_wide_data->_IO_write_ptr = __p, \
535 (__fp)->_wide_data->_IO_write_end = (__ep))
536 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
537 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
538 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
539 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
540 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
541 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
542 - (fp)->_wide_data->_IO_buf_base)
544 /* Jumptable functions for files. */
546 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
547 libc_hidden_proto (_IO_file_doallocate)
548 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
549 libc_hidden_proto (_IO_file_setbuf)
550 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
551 libc_hidden_proto (_IO_file_seekoff)
552 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
553 __THROW;
554 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
555 libc_hidden_proto (_IO_file_xsputn)
556 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
557 libc_hidden_proto (_IO_file_xsgetn)
558 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
559 libc_hidden_proto (_IO_file_stat)
560 extern int _IO_file_close (_IO_FILE *) __THROW;
561 libc_hidden_proto (_IO_file_close)
562 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
563 extern int _IO_file_underflow (_IO_FILE *);
564 libc_hidden_proto (_IO_file_underflow)
565 extern int _IO_file_underflow_mmap (_IO_FILE *);
566 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
567 extern int _IO_file_overflow (_IO_FILE *, int);
568 libc_hidden_proto (_IO_file_overflow)
569 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
570 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
571 libc_hidden_proto (_IO_file_attach)
572 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
573 libc_hidden_proto (_IO_file_open)
574 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
575 libc_hidden_proto (_IO_file_fopen)
576 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
577 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
578 libc_hidden_proto (_IO_file_read)
579 extern int _IO_file_sync (_IO_FILE *);
580 libc_hidden_proto (_IO_file_sync)
581 extern int _IO_file_close_it (_IO_FILE *);
582 libc_hidden_proto (_IO_file_close_it)
583 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
584 libc_hidden_proto (_IO_file_seek)
585 extern void _IO_file_finish (_IO_FILE *, int);
586 libc_hidden_proto (_IO_file_finish)
588 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
589 extern int _IO_new_file_close_it (_IO_FILE *);
590 extern void _IO_new_file_finish (_IO_FILE *, int);
591 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
592 int);
593 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
594 const struct _IO_jump_t *) __THROW;
595 extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
596 __THROW attribute_hidden;
597 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
598 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
599 extern int _IO_new_file_sync (_IO_FILE *);
600 extern int _IO_new_file_underflow (_IO_FILE *);
601 extern int _IO_new_file_overflow (_IO_FILE *, int);
602 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
603 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
604 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
606 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
607 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
608 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
609 extern int _IO_old_file_underflow (_IO_FILE *);
610 extern int _IO_old_file_overflow (_IO_FILE *, int);
611 extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
612 __THROW attribute_hidden;
613 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
614 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
615 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
616 extern int _IO_old_file_sync (_IO_FILE *);
617 extern int _IO_old_file_close_it (_IO_FILE *);
618 extern void _IO_old_file_finish (_IO_FILE *, int);
620 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
621 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
622 libc_hidden_proto (_IO_wfile_xsputn)
623 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
624 extern wint_t _IO_wfile_sync (_IO_FILE *);
625 libc_hidden_proto (_IO_wfile_sync)
626 extern wint_t _IO_wfile_underflow (_IO_FILE *);
627 libc_hidden_proto (_IO_wfile_underflow)
628 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
629 libc_hidden_proto (_IO_wfile_overflow)
630 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
631 libc_hidden_proto (_IO_wfile_seekoff)
633 /* Jumptable functions for proc_files. */
634 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
635 __THROW;
636 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
637 __THROW;
638 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
639 extern int _IO_proc_close (_IO_FILE *) __THROW;
640 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
641 extern int _IO_old_proc_close (_IO_FILE *);
643 /* Jumptable functions for strfiles. */
644 extern int _IO_str_underflow (_IO_FILE *) __THROW;
645 libc_hidden_proto (_IO_str_underflow)
646 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
647 libc_hidden_proto (_IO_str_overflow)
648 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
649 libc_hidden_proto (_IO_str_pbackfail)
650 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
651 libc_hidden_proto (_IO_str_seekoff)
652 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
654 /* Other strfile functions */
655 struct _IO_strfile_;
656 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
658 /* And the wide character versions. */
659 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
660 __THROW;
661 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
662 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
663 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
664 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
665 __THROW;
666 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
667 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
669 extern int _IO_vasprintf (char **result_ptr, const char *format,
670 _IO_va_list args) __THROW;
671 extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
672 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
673 const char *format, _IO_va_list args) __THROW;
676 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
677 libc_hidden_proto (_IO_getline)
678 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
679 int, int, int *);
680 libc_hidden_proto (_IO_getline_info)
681 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
682 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
683 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
684 wint_t, int, wint_t *);
686 extern struct _IO_FILE_plus *_IO_list_all;
687 libc_hidden_proto (_IO_list_all)
688 extern void (*_IO_cleanup_registration_needed) (void);
690 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
691 _IO_size_t, char *) __THROW;
692 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
693 attribute_hidden;
694 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
695 attribute_hidden;
697 #ifndef EOF
698 # define EOF (-1)
699 #endif
701 #if _G_HAVE_MMAP
703 # include <unistd.h>
704 # include <fcntl.h>
705 # include <sys/mman.h>
706 # include <sys/param.h>
708 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
709 # define MAP_ANONYMOUS MAP_ANON
710 # endif
712 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
713 # undef _G_HAVE_MMAP
714 # define _G_HAVE_MMAP 0
715 # endif
717 #endif /* _G_HAVE_MMAP */
719 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
721 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
722 #ifndef _IO_pos_BAD
723 # define _IO_pos_BAD ((_IO_off64_t) -1)
724 #endif
725 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
726 #ifndef _IO_pos_adjust
727 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
728 #endif
729 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
730 #ifndef _IO_pos_0
731 # define _IO_pos_0 ((_IO_off64_t) 0)
732 #endif
734 #ifdef __cplusplus
736 #endif
738 #ifdef _IO_MTSAFE_IO
739 /* check following! */
740 # ifdef _IO_USE_OLD_IO_FILE
741 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
742 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
743 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
744 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
745 # else
746 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
747 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
748 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
749 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
750 NULL, WDP, 0 }
751 # endif
752 #else
753 # ifdef _IO_USE_OLD_IO_FILE
754 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
755 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
756 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
757 0, _IO_pos_BAD }
758 # else
759 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
760 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
761 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
762 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
763 NULL, WDP, 0 }
764 # endif
765 #endif
767 #define _IO_va_start(args, last) va_start(args, last)
769 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
771 #if 1
772 # define COERCE_FILE(FILE) /* Nothing */
773 #else
774 /* This is part of the kludge for binary compatibility with old stdio. */
775 # define COERCE_FILE(FILE) \
776 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
777 && (FILE) = *(FILE**)&((int*)fp)[1])
778 #endif
780 #ifdef EINVAL
781 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
782 #else
783 # define MAYBE_SET_EINVAL /* nothing */
784 #endif
786 #ifdef IO_DEBUG
787 # define CHECK_FILE(FILE, RET) \
788 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
789 else { COERCE_FILE(FILE); \
790 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
791 { MAYBE_SET_EINVAL; return RET; }}
792 #else
793 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
794 #endif
796 static inline void
797 __attribute__ ((__always_inline__))
798 _IO_acquire_lock_fct (_IO_FILE **p)
800 _IO_FILE *fp = *p;
801 if ((fp->_flags & _IO_USER_LOCK) == 0)
802 _IO_funlockfile (fp);
805 static inline void
806 __attribute__ ((__always_inline__))
807 _IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
809 _IO_FILE *fp = *p;
810 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
811 if ((fp->_flags & _IO_USER_LOCK) == 0)
812 _IO_funlockfile (fp);
815 #if !defined _IO_MTSAFE_IO && IS_IN (libc)
816 # define _IO_acquire_lock(_fp) \
817 do { \
818 _IO_FILE *_IO_acquire_lock_file = NULL
819 # define _IO_acquire_lock_clear_flags2(_fp) \
820 do { \
821 _IO_FILE *_IO_acquire_lock_file = (_fp)
822 # define _IO_release_lock(_fp) \
823 if (_IO_acquire_lock_file != NULL) \
824 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
825 | _IO_FLAGS2_SCANF_STD); \
826 } while (0)
827 #endif
829 /* Collect all vtables in a special section for vtable verification.
830 These symbols cover the extent of this section. */
831 symbol_set_declare (__libc_IO_vtables)
833 /* libio vtables need to carry this attribute so that they pass
834 validation. */
835 #define libio_vtable __attribute__ ((section ("__libc_IO_vtables")))
837 #ifdef SHARED
838 /* If equal to &_IO_vtable_check (with pointer guard protection),
839 unknown vtable pointers are valid. This function pointer is solely
840 used as a flag. */
841 extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
843 /* Assigns the passed function pointer (either NULL or
844 &_IO_vtable_check) to IO_accept_foreign_vtables. */
845 static inline void
846 IO_set_accept_foreign_vtables (void (*flag) (void))
848 #ifdef PTR_MANGLE
849 PTR_MANGLE (flag);
850 #endif
851 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
854 #else /* !SHARED */
856 /* The statically-linked version does nothing. */
857 static inline void
858 IO_set_accept_foreign_vtables (void (*flag) (void))
862 #endif
864 /* Check if unknown vtable pointers are permitted; otherwise,
865 terminate the process. */
866 void _IO_vtable_check (void) attribute_hidden;
868 /* Perform vtable pointer validation. If validation fails, terminate
869 the process. */
870 static inline const struct _IO_jump_t *
871 IO_validate_vtable (const struct _IO_jump_t *vtable)
873 /* Fast path: The vtable pointer is within the __libc_IO_vtables
874 section. */
875 uintptr_t section_length = __stop___libc_IO_vtables - __start___libc_IO_vtables;
876 const char *ptr = (const char *) vtable;
877 uintptr_t offset = ptr - __start___libc_IO_vtables;
878 if (__glibc_unlikely (offset >= section_length))
879 /* The vtable pointer is not in the expected section. Use the
880 slow path, which will terminate the process if necessary. */
881 _IO_vtable_check ();
882 return vtable;
885 #endif /* libioP.h. */