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