support: Reformat Makefile.
[glibc.git] / libio / libioP.h
blobd777553cb02477b27f0ca16dfac0081762b90c65
1 /* Copyright (C) 1993-2023 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 <https://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>
50 #include <pointer_guard.h>
52 /* For historical reasons this is the name of the sysdeps header that
53 adjusts the libio configuration. */
54 #include <_G_config.h>
56 #define _IO_seek_set 0
57 #define _IO_seek_cur 1
58 #define _IO_seek_end 2
60 /* THE JUMPTABLE FUNCTIONS.
62 * The _IO_FILE type is used to implement the FILE type in GNU libc,
63 * as well as the streambuf class in GNU iostreams for C++.
64 * These are all the same, just used differently.
65 * An _IO_FILE (or FILE) object is allows followed by a pointer to
66 * a jump table (of pointers to functions). The pointer is accessed
67 * with the _IO_JUMPS macro. The jump table has an eccentric format,
68 * so as to be compatible with the layout of a C++ virtual function table.
69 * (as implemented by g++). When a pointer to a streambuf object is
70 * coerced to an (FILE*), then _IO_JUMPS on the result just
71 * happens to point to the virtual function table of the streambuf.
72 * Thus the _IO_JUMPS function table used for C stdio/libio does
73 * double duty as the virtual function table for C++ streambuf.
75 * The entries in the _IO_JUMPS function table (and hence also the
76 * virtual functions of a streambuf) are described below.
77 * The first parameter of each function entry is the _IO_FILE/streambuf
78 * object being acted on (i.e. the 'this' parameter).
81 /* Setting this macro to 1 enables the use of the _vtable_offset bias
82 in _IO_JUMPS_FUNCS, below. This is only needed for new-format
83 _IO_FILE in libc that must support old binaries (see oldfileops.c). */
84 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) && !defined _IO_USE_OLD_IO_FILE
85 # define _IO_JUMPS_OFFSET 1
86 #else
87 # define _IO_JUMPS_OFFSET 0
88 #endif
90 /* Type of MEMBER in struct type TYPE. */
91 #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
93 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
94 violation in case THIS has a different pointer type. */
95 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
96 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
97 + offsetof(TYPE, MEMBER)))
99 #define _IO_JUMPS(THIS) (THIS)->vtable
100 #define _IO_JUMPS_FILE_plus(THIS) \
101 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
102 #define _IO_WIDE_JUMPS(THIS) \
103 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
104 #define _IO_CHECK_WIDE(THIS) \
105 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
107 #if _IO_JUMPS_OFFSET
108 # define _IO_JUMPS_FUNC(THIS) \
109 (IO_validate_vtable \
110 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
111 + (THIS)->_vtable_offset)))
112 # define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \
113 (*(const struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
114 + (THIS)->_vtable_offset) = (VTABLE))
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_JUMPS_FUNC_UPDATE(THIS, VTABLE) \
119 (_IO_JUMPS_FILE_plus (THIS) = (VTABLE))
120 # define _IO_vtable_offset(THIS) 0
121 #endif
122 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
123 #define JUMP_FIELD(TYPE, NAME) TYPE NAME
124 #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
125 #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
126 #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
127 #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
128 #define JUMP_INIT(NAME, VALUE) VALUE
129 #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
131 #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
132 #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
133 #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
134 #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
136 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
137 It does not delete (free) it, but does everything else to finalize it.
138 It matches the streambuf::~streambuf virtual destructor. */
139 typedef void (*_IO_finish_t) (FILE *, int); /* finalize */
140 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
141 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
143 /* The 'overflow' hook flushes the buffer.
144 The second argument is a character, or EOF.
145 It matches the streambuf::overflow virtual function. */
146 typedef int (*_IO_overflow_t) (FILE *, int);
147 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
148 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
150 /* The 'underflow' hook tries to fills the get buffer.
151 It returns the next character (as an unsigned char) or EOF. The next
152 character remains in the get buffer, and the get position is not changed.
153 It matches the streambuf::underflow virtual function. */
154 typedef int (*_IO_underflow_t) (FILE *);
155 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
156 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
158 /* The 'uflow' hook returns the next character in the input stream
159 (cast to unsigned char), and increments the read position;
160 EOF is returned on failure.
161 It matches the streambuf::uflow virtual function, which is not in the
162 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
163 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
164 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
166 /* The 'pbackfail' hook handles backing up.
167 It matches the streambuf::pbackfail virtual function. */
168 typedef int (*_IO_pbackfail_t) (FILE *, int);
169 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
170 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
172 /* The 'xsputn' hook writes upto N characters from buffer DATA.
173 Returns EOF or the number of character actually written.
174 It matches the streambuf::xsputn virtual function. */
175 typedef size_t (*_IO_xsputn_t) (FILE *FP, const void *DATA,
176 size_t N);
177 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
178 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
180 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
181 Returns the number of character actually read.
182 It matches the streambuf::xsgetn virtual function. */
183 typedef size_t (*_IO_xsgetn_t) (FILE *FP, void *DATA, size_t N);
184 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
185 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
187 /* The 'seekoff' hook moves the stream position to a new position
188 relative to the start of the file (if DIR==0), the current position
189 (MODE==1), or the end of the file (MODE==2).
190 It matches the streambuf::seekoff virtual function.
191 It is also used for the ANSI fseek function. */
192 typedef off64_t (*_IO_seekoff_t) (FILE *FP, off64_t OFF, int DIR,
193 int MODE);
194 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
195 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
197 /* The 'seekpos' hook also moves the stream position,
198 but to an absolute position given by a fpos64_t (seekpos).
199 It matches the streambuf::seekpos virtual function.
200 It is also used for the ANSI fgetpos and fsetpos functions. */
201 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
202 typedef off64_t (*_IO_seekpos_t) (FILE *, off64_t, int);
203 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
204 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
206 /* The 'setbuf' hook gives a buffer to the file.
207 It matches the streambuf::setbuf virtual function. */
208 typedef FILE* (*_IO_setbuf_t) (FILE *, char *, ssize_t);
209 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
210 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
212 /* The 'sync' hook attempts to synchronize the internal data structures
213 of the file with the external state.
214 It matches the streambuf::sync virtual function. */
215 typedef int (*_IO_sync_t) (FILE *);
216 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
217 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
219 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
220 It matches the streambuf::doallocate virtual function, which is not
221 in the ANSI/ISO C++ standard, but is part traditional implementations. */
222 typedef int (*_IO_doallocate_t) (FILE *);
223 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
224 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
226 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
227 sysstat) are low-level hooks specific to this implementation.
228 There is no correspondence in the ANSI/ISO C++ standard library.
229 The hooks basically correspond to the Unix system functions
230 (read, write, close, lseek, and stat) except that a FILE*
231 parameter is used instead of an integer file descriptor; the default
232 implementation used for normal files just calls those functions.
233 The advantage of overriding these functions instead of the higher-level
234 ones (underflow, overflow etc) is that you can leave all the buffering
235 higher-level functions. */
237 /* The 'sysread' hook is used to read data from the external file into
238 an existing buffer. It generalizes the Unix read(2) function.
239 It matches the streambuf::sys_read virtual function, which is
240 specific to this implementation. */
241 typedef ssize_t (*_IO_read_t) (FILE *, void *, ssize_t);
242 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
243 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
245 /* The 'syswrite' hook is used to write data from an existing buffer
246 to an external file. It generalizes the Unix write(2) function.
247 It matches the streambuf::sys_write virtual function, which is
248 specific to this implementation. */
249 typedef ssize_t (*_IO_write_t) (FILE *, const void *, ssize_t);
250 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
251 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
253 /* The 'sysseek' hook is used to re-position an external file.
254 It generalizes the Unix lseek(2) function.
255 It matches the streambuf::sys_seek virtual function, which is
256 specific to this implementation. */
257 typedef off64_t (*_IO_seek_t) (FILE *, off64_t, int);
258 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
259 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
261 /* The 'sysclose' hook is used to finalize (close, finish up) an
262 external file. It generalizes the Unix close(2) function.
263 It matches the streambuf::sys_close virtual function, which is
264 specific to this implementation. */
265 typedef int (*_IO_close_t) (FILE *); /* finalize */
266 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
267 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
269 /* The 'sysstat' hook is used to get information about an external file
270 into a struct stat buffer. It generalizes the Unix fstat(2) call.
271 It matches the streambuf::sys_stat virtual function, which is
272 specific to this implementation. */
273 typedef int (*_IO_stat_t) (FILE *, void *);
274 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
275 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
277 /* The 'showmany' hook can be used to get an image how much input is
278 available. In many cases the answer will be 0 which means unknown
279 but some cases one can provide real information. */
280 typedef int (*_IO_showmanyc_t) (FILE *);
281 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
282 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
284 /* The 'imbue' hook is used to get information about the currently
285 installed locales. */
286 typedef void (*_IO_imbue_t) (FILE *, void *);
287 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
288 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
291 #define _IO_CHAR_TYPE char /* unsigned char ? */
292 #define _IO_INT_TYPE int
294 struct _IO_jump_t
296 JUMP_FIELD(size_t, __dummy);
297 JUMP_FIELD(size_t, __dummy2);
298 JUMP_FIELD(_IO_finish_t, __finish);
299 JUMP_FIELD(_IO_overflow_t, __overflow);
300 JUMP_FIELD(_IO_underflow_t, __underflow);
301 JUMP_FIELD(_IO_underflow_t, __uflow);
302 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
303 /* showmany */
304 JUMP_FIELD(_IO_xsputn_t, __xsputn);
305 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
306 JUMP_FIELD(_IO_seekoff_t, __seekoff);
307 JUMP_FIELD(_IO_seekpos_t, __seekpos);
308 JUMP_FIELD(_IO_setbuf_t, __setbuf);
309 JUMP_FIELD(_IO_sync_t, __sync);
310 JUMP_FIELD(_IO_doallocate_t, __doallocate);
311 JUMP_FIELD(_IO_read_t, __read);
312 JUMP_FIELD(_IO_write_t, __write);
313 JUMP_FIELD(_IO_seek_t, __seek);
314 JUMP_FIELD(_IO_close_t, __close);
315 JUMP_FIELD(_IO_stat_t, __stat);
316 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
317 JUMP_FIELD(_IO_imbue_t, __imbue);
320 /* We always allocate an extra word following an _IO_FILE.
321 This contains a pointer to the function jump table used.
322 This is for compatibility with C++ streambuf; the word can
323 be used to smash to a pointer to a virtual function table. */
325 struct _IO_FILE_plus
327 FILE file;
328 const struct _IO_jump_t *vtable;
331 #ifdef _IO_USE_OLD_IO_FILE
332 /* This structure is used by the compatibility code as if it were an
333 _IO_FILE_plus, but has enough space to initialize the _mode argument
334 of an _IO_FILE_complete. */
335 struct _IO_FILE_complete_plus
337 struct _IO_FILE_complete file;
338 const struct _IO_jump_t *vtable;
340 #endif
342 /* Special file type for fopencookie function. */
343 struct _IO_cookie_file
345 struct _IO_FILE_plus __fp;
346 void *__cookie;
347 cookie_io_functions_t __io_functions;
350 FILE *_IO_fopencookie (void *cookie, const char *mode,
351 cookie_io_functions_t io_functions);
354 /* Iterator type for walking global linked list of _IO_FILE objects. */
356 typedef FILE *_IO_ITER;
358 /* Generic functions */
360 extern void _IO_switch_to_main_get_area (FILE *) __THROW;
361 extern void _IO_switch_to_backup_area (FILE *) __THROW;
362 extern int _IO_switch_to_get_mode (FILE *);
363 libc_hidden_proto (_IO_switch_to_get_mode)
364 extern void _IO_init_internal (FILE *, int) attribute_hidden;
365 extern int _IO_sputbackc (FILE *, int) __THROW;
366 libc_hidden_proto (_IO_sputbackc)
367 extern int _IO_sungetc (FILE *) __THROW;
368 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
369 libc_hidden_proto (_IO_un_link)
370 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
371 libc_hidden_proto (_IO_link_in)
372 extern void _IO_doallocbuf (FILE *) __THROW;
373 libc_hidden_proto (_IO_doallocbuf)
374 extern void _IO_unsave_markers (FILE *) __THROW;
375 libc_hidden_proto (_IO_unsave_markers)
376 extern void _IO_setb (FILE *, char *, char *, int) __THROW;
377 libc_hidden_proto (_IO_setb)
378 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
379 libc_hidden_proto (_IO_adjust_column)
380 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
382 ssize_t _IO_least_wmarker (FILE *, wchar_t *) __THROW;
383 libc_hidden_proto (_IO_least_wmarker)
384 extern void _IO_switch_to_main_wget_area (FILE *) __THROW;
385 libc_hidden_proto (_IO_switch_to_main_wget_area)
386 extern void _IO_switch_to_wbackup_area (FILE *) __THROW;
387 libc_hidden_proto (_IO_switch_to_wbackup_area)
388 extern int _IO_switch_to_wget_mode (FILE *);
389 libc_hidden_proto (_IO_switch_to_wget_mode)
390 extern void _IO_wsetb (FILE *, wchar_t *, wchar_t *, int) __THROW;
391 libc_hidden_proto (_IO_wsetb)
392 extern wint_t _IO_sputbackwc (FILE *, wint_t) __THROW;
393 libc_hidden_proto (_IO_sputbackwc)
394 extern wint_t _IO_sungetwc (FILE *) __THROW;
395 extern void _IO_wdoallocbuf (FILE *) __THROW;
396 libc_hidden_proto (_IO_wdoallocbuf)
397 extern void _IO_unsave_wmarkers (FILE *) __THROW;
398 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
399 extern off64_t get_file_offset (FILE *fp);
401 /* Marker-related function. */
403 extern void _IO_init_marker (struct _IO_marker *, FILE *);
404 extern void _IO_init_wmarker (struct _IO_marker *, FILE *);
405 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
406 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
407 __THROW;
408 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
409 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
410 extern int _IO_seekmark (FILE *, struct _IO_marker *, int) __THROW;
411 extern int _IO_seekwmark (FILE *, struct _IO_marker *, int) __THROW;
413 /* Functions for iterating global list and dealing with its lock */
415 extern _IO_ITER _IO_iter_begin (void) __THROW;
416 libc_hidden_proto (_IO_iter_begin)
417 extern _IO_ITER _IO_iter_end (void) __THROW;
418 libc_hidden_proto (_IO_iter_end)
419 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
420 libc_hidden_proto (_IO_iter_next)
421 extern FILE *_IO_iter_file (_IO_ITER) __THROW;
422 libc_hidden_proto (_IO_iter_file)
423 extern void _IO_list_lock (void) __THROW;
424 libc_hidden_proto (_IO_list_lock)
425 extern void _IO_list_unlock (void) __THROW;
426 libc_hidden_proto (_IO_list_unlock)
427 extern void _IO_list_resetlock (void) __THROW;
428 libc_hidden_proto (_IO_list_resetlock)
429 extern void _IO_enable_locks (void) __THROW;
430 libc_hidden_proto (_IO_enable_locks)
432 /* Default jumptable functions. */
434 extern int _IO_default_underflow (FILE *) __THROW;
435 extern int _IO_default_uflow (FILE *);
436 libc_hidden_proto (_IO_default_uflow)
437 extern wint_t _IO_wdefault_uflow (FILE *);
438 libc_hidden_proto (_IO_wdefault_uflow)
439 extern int _IO_default_doallocate (FILE *) __THROW;
440 libc_hidden_proto (_IO_default_doallocate)
441 extern int _IO_wdefault_doallocate (FILE *) __THROW;
442 libc_hidden_proto (_IO_wdefault_doallocate)
443 extern void _IO_default_finish (FILE *, int) __THROW;
444 libc_hidden_proto (_IO_default_finish)
445 extern void _IO_wdefault_finish (FILE *, int) __THROW;
446 libc_hidden_proto (_IO_wdefault_finish)
447 extern int _IO_default_pbackfail (FILE *, int) __THROW;
448 libc_hidden_proto (_IO_default_pbackfail)
449 extern wint_t _IO_wdefault_pbackfail (FILE *, wint_t) __THROW;
450 libc_hidden_proto (_IO_wdefault_pbackfail)
451 extern FILE* _IO_default_setbuf (FILE *, char *, ssize_t);
452 extern size_t _IO_default_xsputn (FILE *, const void *, size_t);
453 libc_hidden_proto (_IO_default_xsputn)
454 extern size_t _IO_wdefault_xsputn (FILE *, const void *, size_t);
455 libc_hidden_proto (_IO_wdefault_xsputn)
456 extern size_t _IO_default_xsgetn (FILE *, void *, size_t);
457 libc_hidden_proto (_IO_default_xsgetn)
458 extern size_t _IO_wdefault_xsgetn (FILE *, void *, size_t);
459 libc_hidden_proto (_IO_wdefault_xsgetn)
460 extern off64_t _IO_default_seekoff (FILE *, off64_t, int, int)
461 __THROW;
462 extern off64_t _IO_default_seekpos (FILE *, off64_t, int);
463 extern ssize_t _IO_default_write (FILE *, const void *, ssize_t);
464 extern ssize_t _IO_default_read (FILE *, void *, ssize_t);
465 extern int _IO_default_stat (FILE *, void *) __THROW;
466 extern off64_t _IO_default_seek (FILE *, off64_t, int) __THROW;
467 extern int _IO_default_sync (FILE *) __THROW;
468 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
469 extern int _IO_default_showmanyc (FILE *) __THROW;
470 extern void _IO_default_imbue (FILE *, void *) __THROW;
472 extern int __printf_buffer_as_file_overflow (FILE *fp, int ch);
473 extern size_t __printf_buffer_as_file_xsputn (FILE *fp, const void *buf,
474 size_t len);
475 extern wint_t __wprintf_buffer_as_file_overflow (FILE *fp, int ch);
476 extern size_t __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf,
477 size_t len);
479 enum
481 IO_STR_JUMPS = 0,
482 IO_WSTR_JUMPS = 1,
483 IO_FILE_JUMPS = 2,
484 IO_FILE_JUMPS_MMAP = 3,
485 IO_FILE_JUMPS_MAYBE_MMAP = 4,
486 IO_WFILE_JUMPS = 5,
487 IO_WFILE_JUMPS_MMAP = 6,
488 IO_WFILE_JUMPS_MAYBE_MMAP = 7,
489 IO_COOKIE_JUMPS = 8,
490 IO_PROC_JUMPS = 9,
491 IO_MEM_JUMPS = 10,
492 IO_WMEM_JUMPS = 11,
493 IO_PRINTF_BUFFER_AS_FILE_JUMPS = 12,
494 IO_WPRINTF_BUFFER_AS_FILE_JUMPS = 13,
495 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
496 IO_OLD_FILE_JUMPS = 14,
497 IO_OLD_PROC_JUMPS = 15,
498 IO_OLD_COOKIED_JUMPS = 16,
499 IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1,
500 #elif SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
501 IO_OLD_COOKIED_JUMPS = 14,
502 IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1,
503 #else
504 IO_VTABLES_NUM = IO_WPRINTF_BUFFER_AS_FILE_JUMPS + 1
505 #endif
507 #define IO_VTABLES_LEN (IO_VTABLES_NUM * sizeof (struct _IO_jump_t))
509 extern const struct _IO_jump_t __io_vtables[] attribute_hidden;
510 #define _IO_str_jumps (__io_vtables[IO_STR_JUMPS])
511 #define _IO_wstr_jumps (__io_vtables[IO_WSTR_JUMPS])
512 #define _IO_file_jumps (__io_vtables[IO_FILE_JUMPS])
513 #define _IO_file_jumps_mmap (__io_vtables[IO_FILE_JUMPS_MMAP])
514 #define _IO_file_jumps_maybe_mmap (__io_vtables[IO_FILE_JUMPS_MAYBE_MMAP])
515 #define _IO_wfile_jumps (__io_vtables[IO_WFILE_JUMPS])
516 #define _IO_wfile_jumps_mmap (__io_vtables[IO_WFILE_JUMPS_MMAP])
517 #define _IO_wfile_jumps_maybe_mmap (__io_vtables[IO_WFILE_JUMPS_MAYBE_MMAP])
518 #define _IO_cookie_jumps (__io_vtables[IO_COOKIE_JUMPS])
519 #define _IO_proc_jumps (__io_vtables[IO_PROC_JUMPS])
520 #define _IO_mem_jumps (__io_vtables[IO_MEM_JUMPS])
521 #define _IO_wmem_jumps (__io_vtables[IO_WMEM_JUMPS])
522 #define _IO_printf_buffer_as_file_jumps (__io_vtables[IO_PRINTF_BUFFER_AS_FILE_JUMPS])
523 #define _IO_wprintf_buffer_as_file_jumps (__io_vtables[IO_WPRINTF_BUFFER_AS_FILE_JUMPS])
524 #define _IO_old_file_jumps (__io_vtables[IO_OLD_FILE_JUMPS])
525 #define _IO_old_proc_jumps (__io_vtables[IO_OLD_PROC_JUMPS])
526 #define _IO_old_cookie_jumps (__io_vtables[IO_OLD_COOKIED_JUMPS])
528 #ifdef SHARED
529 # define libio_static_fn_required(name)
530 #else
531 # define libio_static_fn_required(name) __asm (".globl " #name);
532 #endif
534 extern int _IO_do_write (FILE *, const char *, size_t);
535 libc_hidden_proto (_IO_do_write)
536 extern int _IO_new_do_write (FILE *, const char *, size_t);
537 extern int _IO_old_do_write (FILE *, const char *, size_t);
538 extern int _IO_wdo_write (FILE *, const wchar_t *, size_t);
539 libc_hidden_proto (_IO_wdo_write)
540 extern int _IO_flush_all_lockp (int);
541 extern int _IO_flush_all (void);
542 libc_hidden_proto (_IO_flush_all)
543 extern void _IO_flush_all_linebuffered (void);
544 libc_hidden_proto (_IO_flush_all_linebuffered)
545 extern int _IO_new_fgetpos (FILE *, __fpos_t *);
546 extern int _IO_old_fgetpos (FILE *, __fpos_t *);
547 extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
548 extern int _IO_old_fsetpos (FILE *, const __fpos_t *);
549 extern int _IO_new_fgetpos64 (FILE *, __fpos64_t *);
550 extern int _IO_old_fgetpos64 (FILE *, __fpos64_t *);
551 extern int _IO_new_fsetpos64 (FILE *, const __fpos64_t *);
552 extern int _IO_old_fsetpos64 (FILE *, const __fpos64_t *);
553 extern void _IO_old_init (FILE *fp, int flags) __THROW;
556 #define _IO_do_flush(_f) \
557 ((_f)->_mode <= 0 \
558 ? _IO_do_write(_f, (_f)->_IO_write_base, \
559 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
560 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
561 ((_f)->_wide_data->_IO_write_ptr \
562 - (_f)->_wide_data->_IO_write_base)))
563 #define _IO_old_do_flush(_f) \
564 _IO_old_do_write(_f, (_f)->_IO_write_base, \
565 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
566 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
567 #define _IO_mask_flags(fp, f, mask) \
568 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
569 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
570 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
571 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
572 (fp)->_wide_data->_IO_read_ptr = (g), \
573 (fp)->_wide_data->_IO_read_end = (eg))
574 #define _IO_setp(__fp, __p, __ep) \
575 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
576 = __p, (__fp)->_IO_write_end = (__ep))
577 #define _IO_wsetp(__fp, __p, __ep) \
578 ((__fp)->_wide_data->_IO_write_base \
579 = (__fp)->_wide_data->_IO_write_ptr = __p, \
580 (__fp)->_wide_data->_IO_write_end = (__ep))
581 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
582 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
583 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
584 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
585 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
586 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
587 - (fp)->_wide_data->_IO_buf_base)
589 /* Jumptable functions for files. */
591 extern int _IO_file_doallocate (FILE *) __THROW;
592 libc_hidden_proto (_IO_file_doallocate)
593 extern FILE* _IO_file_setbuf (FILE *, char *, ssize_t);
594 libc_hidden_proto (_IO_file_setbuf)
595 extern off64_t _IO_file_seekoff (FILE *, off64_t, int, int);
596 libc_hidden_proto (_IO_file_seekoff)
597 extern off64_t _IO_file_seekoff_mmap (FILE *, off64_t, int, int)
598 __THROW;
599 extern size_t _IO_file_xsputn (FILE *, const void *, size_t);
600 libc_hidden_proto (_IO_file_xsputn)
601 extern size_t _IO_file_xsgetn (FILE *, void *, size_t);
602 libc_hidden_proto (_IO_file_xsgetn)
603 extern int _IO_file_stat (FILE *, void *) __THROW;
604 libc_hidden_proto (_IO_file_stat)
605 extern int _IO_file_close (FILE *) __THROW;
606 libc_hidden_proto (_IO_file_close)
607 extern int _IO_file_close_mmap (FILE *) __THROW;
608 extern int _IO_file_underflow (FILE *);
609 libc_hidden_proto (_IO_file_underflow)
610 extern int _IO_file_underflow_mmap (FILE *);
611 extern int _IO_file_underflow_maybe_mmap (FILE *);
612 extern int _IO_file_overflow (FILE *, int);
613 libc_hidden_proto (_IO_file_overflow)
614 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
615 extern FILE* _IO_file_attach (FILE *, int);
616 libc_hidden_proto (_IO_file_attach)
617 extern FILE* _IO_file_open (FILE *, const char *, int, int, int, int);
618 libc_hidden_proto (_IO_file_open)
619 extern FILE* _IO_file_fopen (FILE *, const char *, const char *, int);
620 libc_hidden_proto (_IO_file_fopen)
621 extern ssize_t _IO_file_write (FILE *, const void *, ssize_t);
622 extern ssize_t _IO_file_read (FILE *, void *, ssize_t);
623 libc_hidden_proto (_IO_file_read)
624 extern int _IO_file_sync (FILE *);
625 libc_hidden_proto (_IO_file_sync)
626 extern int _IO_file_close_it (FILE *);
627 libc_hidden_proto (_IO_file_close_it)
628 extern off64_t _IO_file_seek (FILE *, off64_t, int) __THROW;
629 libc_hidden_proto (_IO_file_seek)
630 extern void _IO_file_finish (FILE *, int);
631 libc_hidden_proto (_IO_file_finish)
633 extern FILE* _IO_new_file_attach (FILE *, int);
634 extern int _IO_new_file_close_it (FILE *);
635 extern void _IO_new_file_finish (FILE *, int);
636 extern FILE* _IO_new_file_fopen (FILE *, const char *, const char *,
637 int);
638 extern void _IO_no_init (FILE *, int, int, struct _IO_wide_data *,
639 const struct _IO_jump_t *) __THROW;
640 extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
641 __THROW attribute_hidden;
642 extern FILE* _IO_new_file_setbuf (FILE *, char *, ssize_t);
643 extern FILE* _IO_file_setbuf_mmap (FILE *, char *, ssize_t);
644 extern int _IO_new_file_sync (FILE *);
645 extern int _IO_file_sync_mmap (FILE *) attribute_hidden;
646 extern size_t _IO_file_xsgetn_maybe_mmap (FILE *fp, void *data, size_t n)
647 attribute_hidden;
648 extern size_t _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n)
649 attribute_hidden;
650 extern off64_t _IO_file_seekoff_maybe_mmap (FILE *fp, off64_t offset, int dir,
651 int mode)
652 attribute_hidden;
653 extern int _IO_new_file_underflow (FILE *);
654 extern int _IO_new_file_overflow (FILE *, int);
655 extern off64_t _IO_new_file_seekoff (FILE *, off64_t, int, int);
656 extern ssize_t _IO_new_file_write (FILE *, const void *, ssize_t);
657 extern size_t _IO_new_file_xsputn (FILE *, const void *, size_t);
659 extern FILE* _IO_old_file_setbuf (FILE *, char *, ssize_t);
660 extern off64_t _IO_old_file_seekoff (FILE *, off64_t, int, int);
661 extern size_t _IO_old_file_xsputn (FILE *, const void *, size_t);
662 extern int _IO_old_file_underflow (FILE *);
663 extern int _IO_old_file_overflow (FILE *, int);
664 extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
665 __THROW attribute_hidden;
666 extern FILE* _IO_old_file_attach (FILE *, int);
667 extern FILE* _IO_old_file_fopen (FILE *, const char *, const char *);
668 extern ssize_t _IO_old_file_write (FILE *, const void *, ssize_t);
669 extern int _IO_old_file_sync (FILE *);
670 extern int _IO_old_file_close_it (FILE *);
671 extern void _IO_old_file_finish (FILE *, int);
673 extern int _IO_wfile_doallocate (FILE *) __THROW;
674 extern size_t _IO_wfile_xsputn (FILE *, const void *, size_t);
675 libc_hidden_proto (_IO_wfile_xsputn)
676 extern FILE* _IO_wfile_setbuf (FILE *, wchar_t *, ssize_t);
677 extern wint_t _IO_wfile_sync (FILE *);
678 libc_hidden_proto (_IO_wfile_sync)
679 extern wint_t _IO_wfile_underflow (FILE *);
680 libc_hidden_proto (_IO_wfile_underflow)
681 extern wint_t _IO_wfile_overflow (FILE *, wint_t);
682 libc_hidden_proto (_IO_wfile_overflow)
683 extern off64_t _IO_wfile_seekoff (FILE *, off64_t, int, int);
684 libc_hidden_proto (_IO_wfile_seekoff)
685 extern wint_t _IO_wfile_underflow_maybe_mmap (FILE *fp)
686 attribute_hidden;
687 extern wint_t _IO_wfile_underflow_mmap (FILE *fp)
688 attribute_hidden;
690 /* Jumptable functions for proc_files. */
691 extern FILE* _IO_proc_open (FILE *, const char *, const char *)
692 __THROW;
693 extern FILE* _IO_new_proc_open (FILE *, const char *, const char *)
694 __THROW;
695 extern FILE* _IO_old_proc_open (FILE *, const char *, const char *);
696 extern int _IO_proc_close (FILE *) __THROW;
697 extern int _IO_new_proc_close (FILE *) __THROW;
698 extern int _IO_old_proc_close (FILE *);
700 /* Jumptable functions for strfiles. */
701 extern int _IO_str_underflow (FILE *) __THROW;
702 libc_hidden_proto (_IO_str_underflow)
703 extern int _IO_str_overflow (FILE *, int) __THROW;
704 libc_hidden_proto (_IO_str_overflow)
705 extern int _IO_str_pbackfail (FILE *, int) __THROW;
706 libc_hidden_proto (_IO_str_pbackfail)
707 extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW
709 libc_hidden_proto (_IO_str_seekoff)
710 extern void _IO_str_finish (FILE *, int) __THROW;
711 extern int _IO_str_chk_overflow (FILE *fp, int c) __THROW
712 attribute_hidden;
714 /* Jumptable functions for fopencookie. */
715 extern ssize_t _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
716 attribute_hidden;
717 extern ssize_t _IO_cookie_write (FILE *fp, const void *buf, ssize_t size)
718 attribute_hidden;
719 extern off64_t _IO_cookie_seek (FILE *fp, off64_t offset, int dir)
720 attribute_hidden;
721 extern int _IO_cookie_close (FILE *fp) attribute_hidden;
722 extern off64_t _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode)
723 attribute_hidden;
724 extern off64_t _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir)
725 attribute_hidden;
727 /* Jumptable functions for obstack. */
728 extern int __IO_obstack_overflow (FILE *fp, int c) attribute_hidden;
729 extern size_t __IO_obstack_xsputn (FILE *fp, const void *data, size_t n)
730 attribute_hidden;
732 /* Jumptable functions for open_{w}memstream. */
733 extern int _IO_mem_sync (FILE* fp) __THROW attribute_hidden;
734 extern void _IO_mem_finish (FILE* fp, int) __THROW attribute_hidden;
735 extern int _IO_wmem_sync (FILE* fp) __THROW attribute_hidden;
736 extern void _IO_wmem_finish (FILE* fp, int) __THROW attribute_hidden;
738 /* Other strfile functions */
739 struct _IO_strfile_;
740 extern ssize_t _IO_str_count (FILE *) __THROW;
741 extern int _IO_strn_overflow (FILE *fp, int c) __THROW attribute_hidden;
743 /* And the wide character versions. */
744 extern void _IO_wstr_init_static (FILE *, wchar_t *, size_t, wchar_t *)
745 __THROW;
746 extern ssize_t _IO_wstr_count (FILE *) __THROW;
747 extern wint_t _IO_wstr_overflow (FILE *, wint_t) __THROW;
748 extern wint_t _IO_wstr_underflow (FILE *) __THROW;
749 extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int)
750 __THROW;
751 extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW;
752 extern void _IO_wstr_finish (FILE *, int) __THROW;
754 /* Helper functions. */
755 int _IO_helper_overflow (FILE *s, int c);
756 int _IO_whelper_overflow (FILE *s, int c);
758 /* Internal versions of v*printf that take an additional flags
759 parameter. */
760 extern int __vfprintf_internal (FILE *fp, const char *format, va_list ap,
761 unsigned int mode_flags)
762 attribute_hidden;
763 extern int __vfwprintf_internal (FILE *fp, const wchar_t *format, va_list ap,
764 unsigned int mode_flags)
765 attribute_hidden;
767 extern int __vasprintf_internal (char **result_ptr, const char *format,
768 va_list ap, unsigned int mode_flags)
769 attribute_hidden;
770 extern int __vdprintf_internal (int d, const char *format, va_list ap,
771 unsigned int mode_flags)
772 attribute_hidden;
773 extern int __obstack_vprintf_internal (struct obstack *ob, const char *fmt,
774 va_list ap, unsigned int mode_flags)
775 attribute_hidden;
777 /* Note: __vsprintf_internal, unlike vsprintf, does take a maxlen argument,
778 because it's called by both vsprintf and vsprintf_chk. If maxlen is
779 not set to -1, overrunning the buffer will cause a prompt crash.
780 This is the behavior of ordinary (v)sprintf functions, thus they call
781 __vsprintf_internal with that argument set to -1. */
782 extern int __vsprintf_internal (char *string, size_t maxlen,
783 const char *format, va_list ap,
784 unsigned int mode_flags)
785 attribute_hidden;
787 extern int __vsnprintf_internal (char *string, size_t maxlen,
788 const char *format, va_list ap,
789 unsigned int mode_flags)
790 attribute_hidden;
791 extern int __vswprintf_internal (wchar_t *string, size_t maxlen,
792 const wchar_t *format, va_list ap,
793 unsigned int mode_flags)
794 attribute_hidden;
796 /* Flags for __v*printf_internal.
798 PRINTF_LDBL_IS_DBL indicates whether long double values are to be
799 handled as having the same format as double, in which case the flag
800 should be set to one, or as another format, otherwise.
802 PRINTF_FORTIFY, when set to one, indicates that fortification checks
803 are to be performed in input parameters. This is used by the
804 __*printf_chk functions, which are used when _FORTIFY_SOURCE is
805 defined to 1 or 2. Otherwise, such checks are ignored.
807 PRINTF_CHK indicates, to the internal function being called, that the
808 call is originated from one of the __*printf_chk functions.
810 PRINTF_LDBL_USES_FLOAT128 is used on platforms where the long double
811 format used to be different from the IEC 60559 double format *and*
812 also different from the Quadruple 128-bits IEC 60559 format (such as
813 the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
814 format on x86), but was later converted to the Quadruple 128-bits IEC
815 60559 format, which is the same format that the _Float128 always has
816 (hence the `USES_FLOAT128' suffix in the name of the flag). When set
817 to one, this macro indicates that long double values are to be
818 handled as having this new format. Otherwise, they should be handled
819 as the previous format on that platform. */
820 #define PRINTF_LDBL_IS_DBL 0x0001
821 #define PRINTF_FORTIFY 0x0002
822 #define PRINTF_CHK 0x0004
823 #define PRINTF_LDBL_USES_FLOAT128 0x0008
825 extern size_t _IO_getline (FILE *,char *, size_t, int, int);
826 libc_hidden_proto (_IO_getline)
827 extern size_t _IO_getline_info (FILE *,char *, size_t,
828 int, int, int *);
829 libc_hidden_proto (_IO_getline_info)
830 extern size_t _IO_getwline (FILE *,wchar_t *, size_t, wint_t, int);
831 extern size_t _IO_getwline_info (FILE *,wchar_t *, size_t,
832 wint_t, int, wint_t *);
834 extern struct _IO_FILE_plus *_IO_list_all;
835 libc_hidden_proto (_IO_list_all)
836 extern void (*_IO_cleanup_registration_needed) (void);
838 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
839 size_t, char *) __THROW;
840 extern off64_t _IO_seekoff_unlocked (FILE *, off64_t, int, int)
841 attribute_hidden;
842 extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
843 attribute_hidden;
845 #if _G_HAVE_MMAP
847 # include <unistd.h>
848 # include <fcntl.h>
849 # include <sys/mman.h>
850 # include <sys/param.h>
852 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
853 # define MAP_ANONYMOUS MAP_ANON
854 # endif
856 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
857 # undef _G_HAVE_MMAP
858 # define _G_HAVE_MMAP 0
859 # endif
861 #endif /* _G_HAVE_MMAP */
863 /* Flags for __vfscanf_internal and __vfwscanf_internal.
865 SCANF_LDBL_IS_DBL indicates whether long double values are to be
866 handled as having the same format as double, in which case the flag
867 should be set to one, or as another format, otherwise.
869 SCANF_ISOC99_A, when set to one, indicates that the ISO C99 or POSIX
870 behavior of the scanf functions is to be used, i.e. automatic
871 allocation for input strings with %as, %aS and %a[, a GNU extension,
872 is disabled. This is the behavior that the __isoc99_scanf family of
873 functions use. When the flag is set to zero, automatic allocation is
874 enabled.
876 SCANF_ISOC23_BIN_CST, when set to one, indicates the %i accepts
877 binary constants starting 0b or 0B.
879 SCANF_LDBL_USES_FLOAT128 is used on platforms where the long double
880 format used to be different from the IEC 60559 double format *and*
881 also different from the Quadruple 128-bits IEC 60559 format (such as
882 the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
883 format on x86), but was later converted to the Quadruple 128-bits IEC
884 60559 format, which is the same format that the _Float128 always has
885 (hence the `USES_FLOAT128' suffix in the name of the flag). When set
886 to one, this macros indicates that long double values are to be
887 handled as having this new format. Otherwise, they should be handled
888 as the previous format on that platform. */
889 #define SCANF_LDBL_IS_DBL 0x0001
890 #define SCANF_ISOC99_A 0x0002
891 #define SCANF_ISOC23_BIN_CST 0x0004
892 #define SCANF_LDBL_USES_FLOAT128 0x0008
894 extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
895 unsigned int flags)
896 attribute_hidden;
897 extern int __vfwscanf_internal (FILE *fp, const wchar_t *format, va_list argp,
898 unsigned int flags)
899 attribute_hidden;
901 extern int _IO_vscanf (const char *, va_list) __THROW;
903 #ifdef _IO_MTSAFE_IO
904 /* check following! */
905 # ifdef _IO_USE_OLD_IO_FILE
906 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
907 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
908 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
909 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
910 # else
911 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
912 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
913 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
914 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
915 NULL, WDP, 0 }
916 # endif
917 #else
918 # ifdef _IO_USE_OLD_IO_FILE
919 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
920 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
921 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
922 0, _IO_pos_BAD }
923 # else
924 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
925 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
926 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
927 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
928 NULL, WDP, 0 }
929 # endif
930 #endif
932 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
933 /* See oldstdfiles.c. These are the old stream variables. */
934 extern struct _IO_FILE_plus _IO_stdin_;
935 extern struct _IO_FILE_plus _IO_stdout_;
936 extern struct _IO_FILE_plus _IO_stderr_;
938 static inline bool
939 _IO_legacy_file (FILE *fp)
941 return fp == (FILE *) &_IO_stdin_ || fp == (FILE *) &_IO_stdout_
942 || fp == (FILE *) &_IO_stderr_;
944 #endif
946 /* Deallocate a stream if it is heap-allocated. Preallocated
947 stdin/stdout/stderr streams are not deallocated. */
948 static inline void
949 _IO_deallocate_file (FILE *fp)
951 /* The current stream variables. */
952 if (fp == (FILE *) &_IO_2_1_stdin_ || fp == (FILE *) &_IO_2_1_stdout_
953 || fp == (FILE *) &_IO_2_1_stderr_)
954 return;
955 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
956 if (_IO_legacy_file (fp))
957 return;
958 #endif
959 free (fp);
962 #ifdef IO_DEBUG
963 # define CHECK_FILE(FILE, RET) do { \
964 if ((FILE) == NULL \
965 || ((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
967 __set_errno (EINVAL); \
968 return RET; \
970 } while (0)
971 #else
972 # define CHECK_FILE(FILE, RET) do { } while (0)
973 #endif
975 static inline void
976 __attribute__ ((__always_inline__))
977 _IO_acquire_lock_fct (FILE **p)
979 FILE *fp = *p;
980 if ((fp->_flags & _IO_USER_LOCK) == 0)
981 _IO_funlockfile (fp);
984 #if !defined _IO_MTSAFE_IO && IS_IN (libc)
985 # define _IO_acquire_lock(_fp) \
986 do {
987 # define _IO_release_lock(_fp) \
988 } while (0)
989 #endif
991 #ifdef SHARED
992 /* If equal to &_IO_vtable_check (with pointer guard protection),
993 unknown vtable pointers are valid. This function pointer is solely
994 used as a flag. */
995 extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
997 /* Assigns the passed function pointer (either NULL or
998 &_IO_vtable_check) to IO_accept_foreign_vtables. */
999 static inline void
1000 IO_set_accept_foreign_vtables (void (*flag) (void))
1002 PTR_MANGLE (flag);
1003 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
1006 #else /* !SHARED */
1008 /* The statically-linked version does nothing. */
1009 static inline void
1010 IO_set_accept_foreign_vtables (void (*flag) (void))
1014 #endif
1016 /* Check if unknown vtable pointers are permitted; otherwise,
1017 terminate the process. */
1018 void _IO_vtable_check (void) attribute_hidden;
1020 /* Perform vtable pointer validation. If validation fails, terminate
1021 the process. */
1022 static inline const struct _IO_jump_t *
1023 IO_validate_vtable (const struct _IO_jump_t *vtable)
1025 uintptr_t ptr = (uintptr_t) vtable;
1026 uintptr_t offset = ptr - (uintptr_t) &__io_vtables;
1027 if (__glibc_unlikely (offset >= IO_VTABLES_LEN))
1028 /* The vtable pointer is not in the expected section. Use the
1029 slow path, which will terminate the process if necessary. */
1030 _IO_vtable_check ();
1031 return vtable;
1034 /* Character set conversion. */
1036 enum __codecvt_result
1038 __codecvt_ok,
1039 __codecvt_partial,
1040 __codecvt_error,
1041 __codecvt_noconv
1044 enum __codecvt_result __libio_codecvt_out (struct _IO_codecvt *,
1045 __mbstate_t *,
1046 const wchar_t *,
1047 const wchar_t *,
1048 const wchar_t **, char *,
1049 char *, char **)
1050 attribute_hidden;
1051 enum __codecvt_result __libio_codecvt_in (struct _IO_codecvt *,
1052 __mbstate_t *,
1053 const char *, const char *,
1054 const char **, wchar_t *,
1055 wchar_t *, wchar_t **)
1056 attribute_hidden;
1057 int __libio_codecvt_encoding (struct _IO_codecvt *) attribute_hidden;
1058 int __libio_codecvt_length (struct _IO_codecvt *, __mbstate_t *,
1059 const char *, const char *, size_t)
1060 attribute_hidden;
1062 #endif /* libioP.h. */