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