]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libioP.h
Fix configure from ab22e5ec37396f6c6f29d3e3306f6fcc2ebe9d49
[thirdparty/glibc.git] / libio / libioP.h
CommitLineData
26420023 1/* Copyright (C) 1993-2025 Free Software Foundation, Inc.
ae506220 2 Copyright The GNU Toolchain Authors.
41bdb6e2 3 This file is part of the GNU C Library.
40a55d20 4
41bdb6e2
AJ
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.
40a55d20 9
41bdb6e2
AJ
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
40a55d20 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2
AJ
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>.
41bdb6e2
AJ
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. */
96aa2d94 27
b1848fde
SP
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
a4fea3f2
ZW
36#ifndef _LIBIOP_H
37#define _LIBIOP_H 1
38
e69dcccb
FW
39#include <stddef.h>
40
96aa2d94 41#include <errno.h>
5f0704b6 42#include <libc-lock.h>
96aa2d94 43
c6251f03
RM
44#include <math_ldbl_opt.h>
45
a4fea3f2 46#include <stdio.h>
6c6c962a 47#include <libio/libio.h>
96aa2d94
RM
48#include "iolibio.h"
49
63fb8f9a 50#include <shlib-compat.h>
88f4b692 51#include <pointer_guard.h>
63fb8f9a
ZW
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
96aa2d94
RM
57#define _IO_seek_set 0
58#define _IO_seek_cur 1
59#define _IO_seek_end 2
60
f65fd747
UD
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
c0c3f78a 68 * with the _IO_JUMPS macro. The jump table has an eccentric format,
f65fd747 69 * so as to be compatible with the layout of a C++ virtual function table.
6d52618b 70 * (as implemented by g++). When a pointer to a streambuf object is
9964a145 71 * coerced to an (FILE*), then _IO_JUMPS on the result just
f65fd747
UD
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
6d52618b 74 * double duty as the virtual function table for C++ streambuf.
f65fd747
UD
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 */
96aa2d94 81
63fb8f9a
ZW
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
bd355af0 86# define _IO_JUMPS_OFFSET 1
8f2f08d0
RM
87#else
88# define _IO_JUMPS_OFFSET 0
bd355af0
UD
89#endif
90
e69dcccb
FW
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)) \
7348824c 98 + offsetof(TYPE, MEMBER)))
e69dcccb 99
2ca8b1ee 100#define _IO_JUMPS(THIS) (THIS)->vtable
e69dcccb
FW
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)
7163e69e 107
c15cf13a 108#if _IO_JUMPS_OFFSET
bd355af0 109# define _IO_JUMPS_FUNC(THIS) \
db3476af
FW
110 (IO_validate_vtable \
111 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
112 + (THIS)->_vtable_offset)))
cfa61144
FW
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))
bbdef797 116# define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
bd355af0 117#else
db3476af 118# define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
cfa61144
FW
119# define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \
120 (_IO_JUMPS_FILE_plus (THIS) = (VTABLE))
bbdef797 121# define _IO_vtable_offset(THIS) 0
bd355af0 122#endif
6e06ae59 123#define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
28361c5e
JM
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)
96aa2d94 136
f65fd747 137/* The 'finish' function does any final cleaning up of an _IO_FILE object.
110215a9 138 It does not delete (free) it, but does everything else to finalize it.
f65fd747 139 It matches the streambuf::~streambuf virtual destructor. */
9964a145 140typedef void (*_IO_finish_t) (FILE *, int); /* finalize */
40a55d20 141#define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
6e06ae59 142#define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
f65fd747
UD
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. */
9964a145 147typedef int (*_IO_overflow_t) (FILE *, int);
40a55d20 148#define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
6e06ae59 149#define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
f65fd747
UD
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
6d52618b 153 character remains in the get buffer, and the get position is not changed.
f65fd747 154 It matches the streambuf::underflow virtual function. */
9964a145 155typedef int (*_IO_underflow_t) (FILE *);
40a55d20 156#define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
6e06ae59 157#define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
f65fd747
UD
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. */
40a55d20 164#define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
6e06ae59 165#define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
f65fd747
UD
166
167/* The 'pbackfail' hook handles backing up.
168 It matches the streambuf::pbackfail virtual function. */
9964a145 169typedef int (*_IO_pbackfail_t) (FILE *, int);
40a55d20 170#define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
6e06ae59 171#define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
f65fd747
UD
172
173/* The 'xsputn' hook writes upto N characters from buffer DATA.
2b766585 174 Returns EOF or the number of character actually written.
f65fd747 175 It matches the streambuf::xsputn virtual function. */
9964a145
ZW
176typedef size_t (*_IO_xsputn_t) (FILE *FP, const void *DATA,
177 size_t N);
40a55d20 178#define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
6e06ae59 179#define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
f65fd747
UD
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. */
9964a145 184typedef size_t (*_IO_xsgetn_t) (FILE *FP, void *DATA, size_t N);
40a55d20 185#define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
6e06ae59 186#define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
f65fd747
UD
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. */
9964a145 193typedef off64_t (*_IO_seekoff_t) (FILE *FP, off64_t OFF, int DIR,
79937577 194 int MODE);
40a55d20 195#define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
6e06ae59 196#define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
f65fd747
UD
197
198/* The 'seekpos' hook also moves the stream position,
dfd2257a 199 but to an absolute position given by a fpos64_t (seekpos).
f65fd747
UD
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. */
9964a145 203typedef off64_t (*_IO_seekpos_t) (FILE *, off64_t, int);
40a55d20 204#define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
6e06ae59 205#define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
f65fd747
UD
206
207/* The 'setbuf' hook gives a buffer to the file.
208 It matches the streambuf::setbuf virtual function. */
9964a145 209typedef FILE* (*_IO_setbuf_t) (FILE *, char *, ssize_t);
40a55d20 210#define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
6e06ae59 211#define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
f65fd747
UD
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. */
9964a145 216typedef int (*_IO_sync_t) (FILE *);
40a55d20 217#define _IO_SYNC(FP) JUMP0 (__sync, FP)
6e06ae59 218#define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
f65fd747
UD
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. */
9964a145 223typedef int (*_IO_doallocate_t) (FILE *);
40a55d20 224#define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
6e06ae59 225#define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
f65fd747
UD
226
227/* The following four hooks (sysread, syswrite, sysclose, sysseek, and
228 sysstat) are low-level hooks specific to this implementation.
6d52618b 229 There is no correspondence in the ANSI/ISO C++ standard library.
f65fd747 230 The hooks basically correspond to the Unix system functions
9964a145 231 (read, write, close, lseek, and stat) except that a FILE*
c0c3f78a 232 parameter is used instead of an integer file descriptor; the default
f65fd747
UD
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
6d52618b 241 specific to this implementation. */
9964a145 242typedef ssize_t (*_IO_read_t) (FILE *, void *, ssize_t);
40a55d20 243#define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
6e06ae59 244#define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
f65fd747
UD
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
6d52618b 249 specific to this implementation. */
9964a145 250typedef ssize_t (*_IO_write_t) (FILE *, const void *, ssize_t);
40a55d20 251#define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
6e06ae59 252#define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
f65fd747
UD
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
6d52618b 257 specific to this implementation. */
9964a145 258typedef off64_t (*_IO_seek_t) (FILE *, off64_t, int);
40a55d20 259#define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
6e06ae59 260#define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
f65fd747
UD
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. */
9964a145 266typedef int (*_IO_close_t) (FILE *); /* finalize */
40a55d20 267#define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
6e06ae59 268#define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
f65fd747
UD
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
6d52618b 273 specific to this implementation. */
9964a145 274typedef int (*_IO_stat_t) (FILE *, void *);
40a55d20 275#define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
6e06ae59 276#define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
96aa2d94 277
dfd2257a
UD
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. */
9964a145 281typedef int (*_IO_showmanyc_t) (FILE *);
dfd2257a 282#define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
6e06ae59 283#define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
dfd2257a
UD
284
285/* The 'imbue' hook is used to get information about the currently
286 installed locales. */
9964a145 287typedef void (*_IO_imbue_t) (FILE *, void *);
dfd2257a 288#define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
6e06ae59 289#define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
dfd2257a 290
f65fd747 291
96aa2d94
RM
292#define _IO_CHAR_TYPE char /* unsigned char ? */
293#define _IO_INT_TYPE int
294
40a55d20
UD
295struct _IO_jump_t
296{
203e5603
JM
297 JUMP_FIELD(size_t, __dummy);
298 JUMP_FIELD(size_t, __dummy2);
96aa2d94
RM
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);
dfd2257a
UD
317 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
318 JUMP_FIELD(_IO_imbue_t, __imbue);
96aa2d94
RM
319};
320
321/* We always allocate an extra word following an _IO_FILE.
f65fd747 322 This contains a pointer to the function jump table used.
96aa2d94
RM
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
40a55d20
UD
326struct _IO_FILE_plus
327{
9964a145 328 FILE file;
96aa2d94 329 const struct _IO_jump_t *vtable;
96aa2d94
RM
330};
331
7ea11363
UD
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. */
336struct _IO_FILE_complete_plus
337{
338 struct _IO_FILE_complete file;
339 const struct _IO_jump_t *vtable;
340};
341#endif
342
2ca8b1ee
GM
343/* Special file type for fopencookie function. */
344struct _IO_cookie_file
345{
346 struct _IO_FILE_plus __fp;
347 void *__cookie;
9964a145 348 cookie_io_functions_t __io_functions;
2ca8b1ee
GM
349};
350
9964a145
ZW
351FILE *_IO_fopencookie (void *cookie, const char *mode,
352 cookie_io_functions_t io_functions);
c9fc9559
RM
353
354
3fc9ca4e
UD
355/* Iterator type for walking global linked list of _IO_FILE objects. */
356
9964a145 357typedef FILE *_IO_ITER;
3fc9ca4e 358
96aa2d94
RM
359/* Generic functions */
360
9964a145
ZW
361extern void _IO_switch_to_main_get_area (FILE *) __THROW;
362extern void _IO_switch_to_backup_area (FILE *) __THROW;
363extern int _IO_switch_to_get_mode (FILE *);
d18ea0c5 364libc_hidden_proto (_IO_switch_to_get_mode)
9964a145
ZW
365extern void _IO_init_internal (FILE *, int) attribute_hidden;
366extern int _IO_sputbackc (FILE *, int) __THROW;
d18ea0c5 367libc_hidden_proto (_IO_sputbackc)
9964a145 368extern int _IO_sungetc (FILE *) __THROW;
79937577 369extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
d18ea0c5 370libc_hidden_proto (_IO_un_link)
79937577 371extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
d18ea0c5 372libc_hidden_proto (_IO_link_in)
9964a145 373extern void _IO_doallocbuf (FILE *) __THROW;
d18ea0c5 374libc_hidden_proto (_IO_doallocbuf)
9964a145 375extern void _IO_unsave_markers (FILE *) __THROW;
d18ea0c5 376libc_hidden_proto (_IO_unsave_markers)
9964a145 377extern void _IO_setb (FILE *, char *, char *, int) __THROW;
d18ea0c5 378libc_hidden_proto (_IO_setb)
79937577 379extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
d18ea0c5 380libc_hidden_proto (_IO_adjust_column)
40a55d20 381#define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
96aa2d94 382
9964a145 383ssize_t _IO_least_wmarker (FILE *, wchar_t *) __THROW;
d18ea0c5 384libc_hidden_proto (_IO_least_wmarker)
9964a145 385extern void _IO_switch_to_main_wget_area (FILE *) __THROW;
d18ea0c5 386libc_hidden_proto (_IO_switch_to_main_wget_area)
9964a145 387extern void _IO_switch_to_wbackup_area (FILE *) __THROW;
d18ea0c5 388libc_hidden_proto (_IO_switch_to_wbackup_area)
9964a145 389extern int _IO_switch_to_wget_mode (FILE *);
d18ea0c5 390libc_hidden_proto (_IO_switch_to_wget_mode)
9964a145 391extern void _IO_wsetb (FILE *, wchar_t *, wchar_t *, int) __THROW;
d18ea0c5 392libc_hidden_proto (_IO_wsetb)
9964a145 393extern wint_t _IO_sputbackwc (FILE *, wint_t) __THROW;
d18ea0c5 394libc_hidden_proto (_IO_sputbackwc)
9964a145
ZW
395extern wint_t _IO_sungetwc (FILE *) __THROW;
396extern void _IO_wdoallocbuf (FILE *) __THROW;
d18ea0c5 397libc_hidden_proto (_IO_wdoallocbuf)
9964a145 398extern void _IO_unsave_wmarkers (FILE *) __THROW;
79937577 399extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
9964a145 400extern off64_t get_file_offset (FILE *fp);
d64b6ad0 401
96aa2d94
RM
402/* Marker-related function. */
403
9964a145
ZW
404extern void _IO_init_marker (struct _IO_marker *, FILE *);
405extern void _IO_init_wmarker (struct _IO_marker *, FILE *);
79937577
UD
406extern void _IO_remove_marker (struct _IO_marker *) __THROW;
407extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
408 __THROW;
409extern int _IO_marker_delta (struct _IO_marker *) __THROW;
410extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
9964a145
ZW
411extern int _IO_seekmark (FILE *, struct _IO_marker *, int) __THROW;
412extern int _IO_seekwmark (FILE *, struct _IO_marker *, int) __THROW;
96aa2d94 413
79937577 414/* Functions for iterating global list and dealing with its lock */
3fc9ca4e 415
79937577 416extern _IO_ITER _IO_iter_begin (void) __THROW;
1d2b6e0c 417libc_hidden_proto (_IO_iter_begin)
79937577 418extern _IO_ITER _IO_iter_end (void) __THROW;
1d2b6e0c 419libc_hidden_proto (_IO_iter_end)
79937577 420extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
1d2b6e0c 421libc_hidden_proto (_IO_iter_next)
9964a145 422extern FILE *_IO_iter_file (_IO_ITER) __THROW;
1d2b6e0c 423libc_hidden_proto (_IO_iter_file)
79937577 424extern void _IO_list_lock (void) __THROW;
245eab02 425libc_hidden_proto (_IO_list_lock)
79937577 426extern void _IO_list_unlock (void) __THROW;
245eab02 427libc_hidden_proto (_IO_list_unlock)
79937577 428extern void _IO_list_resetlock (void) __THROW;
245eab02 429libc_hidden_proto (_IO_list_resetlock)
d2e04918
SN
430extern void _IO_enable_locks (void) __THROW;
431libc_hidden_proto (_IO_enable_locks)
3fc9ca4e 432
9f0d2c0e
AS
433/* Functions for operating popen's proc_file_chain_lock during fork. */
434
435extern void _IO_proc_file_chain_lock (void) __THROW attribute_hidden;
436extern void _IO_proc_file_chain_unlock (void) __THROW attribute_hidden;
437extern void _IO_proc_file_chain_resetlock (void) __THROW attribute_hidden;
438
96aa2d94
RM
439/* Default jumptable functions. */
440
9964a145
ZW
441extern int _IO_default_underflow (FILE *) __THROW;
442extern int _IO_default_uflow (FILE *);
d18ea0c5 443libc_hidden_proto (_IO_default_uflow)
9964a145 444extern wint_t _IO_wdefault_uflow (FILE *);
d18ea0c5 445libc_hidden_proto (_IO_wdefault_uflow)
9964a145 446extern int _IO_default_doallocate (FILE *) __THROW;
d18ea0c5 447libc_hidden_proto (_IO_default_doallocate)
9964a145 448extern int _IO_wdefault_doallocate (FILE *) __THROW;
d18ea0c5 449libc_hidden_proto (_IO_wdefault_doallocate)
9964a145 450extern void _IO_default_finish (FILE *, int) __THROW;
d18ea0c5 451libc_hidden_proto (_IO_default_finish)
9964a145 452extern void _IO_wdefault_finish (FILE *, int) __THROW;
d18ea0c5 453libc_hidden_proto (_IO_wdefault_finish)
9964a145 454extern int _IO_default_pbackfail (FILE *, int) __THROW;
d18ea0c5 455libc_hidden_proto (_IO_default_pbackfail)
9964a145 456extern wint_t _IO_wdefault_pbackfail (FILE *, wint_t) __THROW;
d18ea0c5 457libc_hidden_proto (_IO_wdefault_pbackfail)
9964a145
ZW
458extern FILE* _IO_default_setbuf (FILE *, char *, ssize_t);
459extern size_t _IO_default_xsputn (FILE *, const void *, size_t);
d18ea0c5 460libc_hidden_proto (_IO_default_xsputn)
9964a145 461extern size_t _IO_wdefault_xsputn (FILE *, const void *, size_t);
d18ea0c5 462libc_hidden_proto (_IO_wdefault_xsputn)
9964a145 463extern size_t _IO_default_xsgetn (FILE *, void *, size_t);
d18ea0c5 464libc_hidden_proto (_IO_default_xsgetn)
9964a145 465extern size_t _IO_wdefault_xsgetn (FILE *, void *, size_t);
d18ea0c5 466libc_hidden_proto (_IO_wdefault_xsgetn)
9964a145 467extern off64_t _IO_default_seekoff (FILE *, off64_t, int, int)
79937577 468 __THROW;
9964a145
ZW
469extern off64_t _IO_default_seekpos (FILE *, off64_t, int);
470extern ssize_t _IO_default_write (FILE *, const void *, ssize_t);
471extern ssize_t _IO_default_read (FILE *, void *, ssize_t);
472extern int _IO_default_stat (FILE *, void *) __THROW;
473extern off64_t _IO_default_seek (FILE *, off64_t, int) __THROW;
474extern int _IO_default_sync (FILE *) __THROW;
40a55d20 475#define _IO_default_close ((_IO_close_t) _IO_default_sync)
9964a145
ZW
476extern int _IO_default_showmanyc (FILE *) __THROW;
477extern void _IO_default_imbue (FILE *, void *) __THROW;
96aa2d94 478
3020f726
AZN
479extern int __printf_buffer_as_file_overflow (FILE *fp, int ch);
480extern size_t __printf_buffer_as_file_xsputn (FILE *fp, const void *buf,
481 size_t len);
482extern wint_t __wprintf_buffer_as_file_overflow (FILE *fp, int ch);
483extern size_t __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf,
484 size_t len);
485
486enum
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
516extern 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
b4ab549a
L
538# define libio_static_fn_required(name) \
539 static __typeof (name) *const name##_p __attribute__((used)) = name;
3020f726
AZN
540#endif
541
9964a145 542extern int _IO_do_write (FILE *, const char *, size_t);
d18ea0c5 543libc_hidden_proto (_IO_do_write)
9964a145
ZW
544extern int _IO_new_do_write (FILE *, const char *, size_t);
545extern int _IO_old_do_write (FILE *, const char *, size_t);
546extern int _IO_wdo_write (FILE *, const wchar_t *, size_t);
d18ea0c5 547libc_hidden_proto (_IO_wdo_write)
0fca3153 548extern int _IO_flush_all (void);
d18ea0c5 549libc_hidden_proto (_IO_flush_all)
0fca3153 550extern void _IO_flush_all_linebuffered (void);
d18ea0c5 551libc_hidden_proto (_IO_flush_all_linebuffered)
9964a145
ZW
552extern int _IO_new_fgetpos (FILE *, __fpos_t *);
553extern int _IO_old_fgetpos (FILE *, __fpos_t *);
554extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
555extern int _IO_old_fsetpos (FILE *, const __fpos_t *);
556extern int _IO_new_fgetpos64 (FILE *, __fpos64_t *);
557extern int _IO_old_fgetpos64 (FILE *, __fpos64_t *);
558extern int _IO_new_fsetpos64 (FILE *, const __fpos64_t *);
559extern int _IO_old_fsetpos64 (FILE *, const __fpos64_t *);
560extern void _IO_old_init (FILE *fp, int flags) __THROW;
d64b6ad0 561
96aa2d94 562
5f0704b6 563#define _IO_do_flush(_f) \
d64b6ad0 564 ((_f)->_mode <= 0 \
d18ea0c5
AS
565 ? _IO_do_write(_f, (_f)->_IO_write_base, \
566 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
567 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
568 ((_f)->_wide_data->_IO_write_ptr \
569 - (_f)->_wide_data->_IO_write_base)))
6973fc01
UD
570#define _IO_old_do_flush(_f) \
571 _IO_old_do_write(_f, (_f)->_IO_write_base, \
572 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
96aa2d94
RM
573#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
574#define _IO_mask_flags(fp, f, mask) \
575 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
576#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
577 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
d64b6ad0
UD
578#define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
579 (fp)->_wide_data->_IO_read_ptr = (g), \
580 (fp)->_wide_data->_IO_read_end = (eg))
96aa2d94 581#define _IO_setp(__fp, __p, __ep) \
d64b6ad0
UD
582 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
583 = __p, (__fp)->_IO_write_end = (__ep))
584#define _IO_wsetp(__fp, __p, __ep) \
585 ((__fp)->_wide_data->_IO_write_base \
586 = (__fp)->_wide_data->_IO_write_ptr = __p, \
587 (__fp)->_wide_data->_IO_write_end = (__ep))
3e1d8d1d
SP
588#define _IO_have_backup(fp) ((fp)->_IO_backup_base != NULL)
589#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_backup_base != NULL)
96aa2d94
RM
590#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
591#define _IO_have_markers(fp) ((fp)->_markers != NULL)
f65fd747 592#define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
d64b6ad0
UD
593#define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
594 - (fp)->_wide_data->_IO_buf_base)
96aa2d94
RM
595
596/* Jumptable functions for files. */
597
9964a145 598extern int _IO_file_doallocate (FILE *) __THROW;
d18ea0c5 599libc_hidden_proto (_IO_file_doallocate)
9964a145 600extern FILE* _IO_file_setbuf (FILE *, char *, ssize_t);
d18ea0c5 601libc_hidden_proto (_IO_file_setbuf)
9964a145 602extern off64_t _IO_file_seekoff (FILE *, off64_t, int, int);
d18ea0c5 603libc_hidden_proto (_IO_file_seekoff)
9964a145 604extern off64_t _IO_file_seekoff_mmap (FILE *, off64_t, int, int)
79937577 605 __THROW;
9964a145 606extern size_t _IO_file_xsputn (FILE *, const void *, size_t);
d18ea0c5 607libc_hidden_proto (_IO_file_xsputn)
9964a145 608extern size_t _IO_file_xsgetn (FILE *, void *, size_t);
d18ea0c5 609libc_hidden_proto (_IO_file_xsgetn)
9964a145 610extern int _IO_file_stat (FILE *, void *) __THROW;
d18ea0c5 611libc_hidden_proto (_IO_file_stat)
9964a145 612extern int _IO_file_close (FILE *) __THROW;
d18ea0c5 613libc_hidden_proto (_IO_file_close)
9964a145
ZW
614extern int _IO_file_close_mmap (FILE *) __THROW;
615extern int _IO_file_underflow (FILE *);
d18ea0c5 616libc_hidden_proto (_IO_file_underflow)
9964a145
ZW
617extern int _IO_file_underflow_mmap (FILE *);
618extern int _IO_file_underflow_maybe_mmap (FILE *);
619extern int _IO_file_overflow (FILE *, int);
d18ea0c5 620libc_hidden_proto (_IO_file_overflow)
110215a9 621#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
9964a145 622extern FILE* _IO_file_attach (FILE *, int);
d18ea0c5 623libc_hidden_proto (_IO_file_attach)
9964a145 624extern FILE* _IO_file_open (FILE *, const char *, int, int, int, int);
ee2a5ae8 625libc_hidden_proto (_IO_file_open)
9964a145 626extern FILE* _IO_file_fopen (FILE *, const char *, const char *, int);
d18ea0c5 627libc_hidden_proto (_IO_file_fopen)
9964a145
ZW
628extern ssize_t _IO_file_write (FILE *, const void *, ssize_t);
629extern ssize_t _IO_file_read (FILE *, void *, ssize_t);
d18ea0c5 630libc_hidden_proto (_IO_file_read)
9964a145 631extern int _IO_file_sync (FILE *);
d18ea0c5 632libc_hidden_proto (_IO_file_sync)
9964a145 633extern int _IO_file_close_it (FILE *);
d18ea0c5 634libc_hidden_proto (_IO_file_close_it)
9964a145 635extern off64_t _IO_file_seek (FILE *, off64_t, int) __THROW;
d18ea0c5 636libc_hidden_proto (_IO_file_seek)
9964a145 637extern void _IO_file_finish (FILE *, int);
d18ea0c5 638libc_hidden_proto (_IO_file_finish)
79937577 639
9964a145
ZW
640extern FILE* _IO_new_file_attach (FILE *, int);
641extern int _IO_new_file_close_it (FILE *);
642extern void _IO_new_file_finish (FILE *, int);
643extern FILE* _IO_new_file_fopen (FILE *, const char *, const char *,
0fca3153 644 int);
9964a145 645extern void _IO_no_init (FILE *, int, int, struct _IO_wide_data *,
79937577 646 const struct _IO_jump_t *) __THROW;
db3476af
FW
647extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
648 __THROW attribute_hidden;
9964a145
ZW
649extern FILE* _IO_new_file_setbuf (FILE *, char *, ssize_t);
650extern FILE* _IO_file_setbuf_mmap (FILE *, char *, ssize_t);
651extern int _IO_new_file_sync (FILE *);
3020f726
AZN
652extern int _IO_file_sync_mmap (FILE *) attribute_hidden;
653extern size_t _IO_file_xsgetn_maybe_mmap (FILE *fp, void *data, size_t n)
654 attribute_hidden;
655extern size_t _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n)
656 attribute_hidden;
657extern off64_t _IO_file_seekoff_maybe_mmap (FILE *fp, off64_t offset, int dir,
658 int mode)
659 attribute_hidden;
9964a145
ZW
660extern int _IO_new_file_underflow (FILE *);
661extern int _IO_new_file_overflow (FILE *, int);
662extern off64_t _IO_new_file_seekoff (FILE *, off64_t, int, int);
663extern ssize_t _IO_new_file_write (FILE *, const void *, ssize_t);
664extern size_t _IO_new_file_xsputn (FILE *, const void *, size_t);
665
666extern FILE* _IO_old_file_setbuf (FILE *, char *, ssize_t);
667extern off64_t _IO_old_file_seekoff (FILE *, off64_t, int, int);
668extern size_t _IO_old_file_xsputn (FILE *, const void *, size_t);
669extern int _IO_old_file_underflow (FILE *);
670extern int _IO_old_file_overflow (FILE *, int);
db3476af
FW
671extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
672 __THROW attribute_hidden;
9964a145
ZW
673extern FILE* _IO_old_file_attach (FILE *, int);
674extern FILE* _IO_old_file_fopen (FILE *, const char *, const char *);
675extern ssize_t _IO_old_file_write (FILE *, const void *, ssize_t);
676extern int _IO_old_file_sync (FILE *);
677extern int _IO_old_file_close_it (FILE *);
678extern void _IO_old_file_finish (FILE *, int);
679
680extern int _IO_wfile_doallocate (FILE *) __THROW;
681extern size_t _IO_wfile_xsputn (FILE *, const void *, size_t);
d18ea0c5 682libc_hidden_proto (_IO_wfile_xsputn)
9964a145
ZW
683extern FILE* _IO_wfile_setbuf (FILE *, wchar_t *, ssize_t);
684extern wint_t _IO_wfile_sync (FILE *);
d18ea0c5 685libc_hidden_proto (_IO_wfile_sync)
9964a145 686extern wint_t _IO_wfile_underflow (FILE *);
d18ea0c5 687libc_hidden_proto (_IO_wfile_underflow)
9964a145 688extern wint_t _IO_wfile_overflow (FILE *, wint_t);
d18ea0c5 689libc_hidden_proto (_IO_wfile_overflow)
9964a145 690extern off64_t _IO_wfile_seekoff (FILE *, off64_t, int, int);
d18ea0c5 691libc_hidden_proto (_IO_wfile_seekoff)
3020f726
AZN
692extern wint_t _IO_wfile_underflow_maybe_mmap (FILE *fp)
693 attribute_hidden;
694extern wint_t _IO_wfile_underflow_mmap (FILE *fp)
695 attribute_hidden;
d64b6ad0 696
96aa2d94 697/* Jumptable functions for proc_files. */
9964a145 698extern FILE* _IO_proc_open (FILE *, const char *, const char *)
79937577 699 __THROW;
9964a145 700extern FILE* _IO_new_proc_open (FILE *, const char *, const char *)
79937577 701 __THROW;
9964a145
ZW
702extern FILE* _IO_old_proc_open (FILE *, const char *, const char *);
703extern int _IO_proc_close (FILE *) __THROW;
704extern int _IO_new_proc_close (FILE *) __THROW;
705extern int _IO_old_proc_close (FILE *);
96aa2d94
RM
706
707/* Jumptable functions for strfiles. */
9964a145 708extern int _IO_str_underflow (FILE *) __THROW;
d18ea0c5 709libc_hidden_proto (_IO_str_underflow)
9964a145 710extern int _IO_str_overflow (FILE *, int) __THROW;
d18ea0c5 711libc_hidden_proto (_IO_str_overflow)
9964a145 712extern int _IO_str_pbackfail (FILE *, int) __THROW;
d18ea0c5 713libc_hidden_proto (_IO_str_pbackfail)
3020f726
AZN
714extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW
715 ;
d18ea0c5 716libc_hidden_proto (_IO_str_seekoff)
9964a145 717extern void _IO_str_finish (FILE *, int) __THROW;
3020f726
AZN
718extern int _IO_str_chk_overflow (FILE *fp, int c) __THROW
719 attribute_hidden;
720
721/* Jumptable functions for fopencookie. */
722extern ssize_t _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
723 attribute_hidden;
724extern ssize_t _IO_cookie_write (FILE *fp, const void *buf, ssize_t size)
725 attribute_hidden;
726extern off64_t _IO_cookie_seek (FILE *fp, off64_t offset, int dir)
727 attribute_hidden;
728extern int _IO_cookie_close (FILE *fp) attribute_hidden;
729extern off64_t _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode)
730 attribute_hidden;
731extern off64_t _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir)
732 attribute_hidden;
733
734/* Jumptable functions for obstack. */
735extern int __IO_obstack_overflow (FILE *fp, int c) attribute_hidden;
736extern size_t __IO_obstack_xsputn (FILE *fp, const void *data, size_t n)
737 attribute_hidden;
738
739/* Jumptable functions for open_{w}memstream. */
740extern int _IO_mem_sync (FILE* fp) __THROW attribute_hidden;
741extern void _IO_mem_finish (FILE* fp, int) __THROW attribute_hidden;
742extern int _IO_wmem_sync (FILE* fp) __THROW attribute_hidden;
743extern void _IO_wmem_finish (FILE* fp, int) __THROW attribute_hidden;
96aa2d94
RM
744
745/* Other strfile functions */
2ca8b1ee 746struct _IO_strfile_;
9964a145 747extern ssize_t _IO_str_count (FILE *) __THROW;
3020f726 748extern int _IO_strn_overflow (FILE *fp, int c) __THROW attribute_hidden;
96aa2d94 749
d64b6ad0 750/* And the wide character versions. */
9964a145 751extern void _IO_wstr_init_static (FILE *, wchar_t *, size_t, wchar_t *)
79937577 752 __THROW;
9964a145
ZW
753extern ssize_t _IO_wstr_count (FILE *) __THROW;
754extern wint_t _IO_wstr_overflow (FILE *, wint_t) __THROW;
755extern wint_t _IO_wstr_underflow (FILE *) __THROW;
756extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int)
79937577 757 __THROW;
9964a145
ZW
758extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW;
759extern void _IO_wstr_finish (FILE *, int) __THROW;
79937577 760
3020f726
AZN
761/* Helper functions. */
762int _IO_helper_overflow (FILE *s, int c);
763int _IO_whelper_overflow (FILE *s, int c);
764
698fb75b
ZW
765/* Internal versions of v*printf that take an additional flags
766 parameter. */
767extern int __vfprintf_internal (FILE *fp, const char *format, va_list ap,
768 unsigned int mode_flags)
769 attribute_hidden;
770extern int __vfwprintf_internal (FILE *fp, const wchar_t *format, va_list ap,
771 unsigned int mode_flags)
772 attribute_hidden;
773
774extern int __vasprintf_internal (char **result_ptr, const char *format,
775 va_list ap, unsigned int mode_flags)
776 attribute_hidden;
777extern int __vdprintf_internal (int d, const char *format, va_list ap,
778 unsigned int mode_flags)
779 attribute_hidden;
780extern int __obstack_vprintf_internal (struct obstack *ob, const char *fmt,
781 va_list ap, unsigned int mode_flags)
782 attribute_hidden;
783
4e2f43f8
ZW
784/* Note: __vsprintf_internal, unlike vsprintf, does take a maxlen argument,
785 because it's called by both vsprintf and vsprintf_chk. If maxlen is
786 not set to -1, overrunning the buffer will cause a prompt crash.
787 This is the behavior of ordinary (v)sprintf functions, thus they call
788 __vsprintf_internal with that argument set to -1. */
789extern int __vsprintf_internal (char *string, size_t maxlen,
790 const char *format, va_list ap,
698fb75b
ZW
791 unsigned int mode_flags)
792 attribute_hidden;
4e2f43f8 793
698fb75b
ZW
794extern int __vsnprintf_internal (char *string, size_t maxlen,
795 const char *format, va_list ap,
796 unsigned int mode_flags)
797 attribute_hidden;
798extern int __vswprintf_internal (wchar_t *string, size_t maxlen,
799 const wchar_t *format, va_list ap,
800 unsigned int mode_flags)
801 attribute_hidden;
802
803/* Flags for __v*printf_internal.
804
805 PRINTF_LDBL_IS_DBL indicates whether long double values are to be
806 handled as having the same format as double, in which case the flag
807 should be set to one, or as another format, otherwise.
808
809 PRINTF_FORTIFY, when set to one, indicates that fortification checks
810 are to be performed in input parameters. This is used by the
811 __*printf_chk functions, which are used when _FORTIFY_SOURCE is
2d9837c1
GG
812 defined to 1 or 2. Otherwise, such checks are ignored.
813
814 PRINTF_CHK indicates, to the internal function being called, that the
1626f499
GG
815 call is originated from one of the __*printf_chk functions.
816
817 PRINTF_LDBL_USES_FLOAT128 is used on platforms where the long double
818 format used to be different from the IEC 60559 double format *and*
819 also different from the Quadruple 128-bits IEC 60559 format (such as
820 the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
821 format on x86), but was later converted to the Quadruple 128-bits IEC
822 60559 format, which is the same format that the _Float128 always has
823 (hence the `USES_FLOAT128' suffix in the name of the flag). When set
824 to one, this macro indicates that long double values are to be
825 handled as having this new format. Otherwise, they should be handled
826 as the previous format on that platform. */
827#define PRINTF_LDBL_IS_DBL 0x0001
828#define PRINTF_FORTIFY 0x0002
829#define PRINTF_CHK 0x0004
830#define PRINTF_LDBL_USES_FLOAT128 0x0008
79937577 831
9964a145 832extern size_t _IO_getline (FILE *,char *, size_t, int, int);
d18ea0c5 833libc_hidden_proto (_IO_getline)
9964a145 834extern size_t _IO_getline_info (FILE *,char *, size_t,
102070bc 835 int, int, int *);
d18ea0c5 836libc_hidden_proto (_IO_getline_info)
9964a145
ZW
837extern size_t _IO_getwline (FILE *,wchar_t *, size_t, wint_t, int);
838extern size_t _IO_getwline_info (FILE *,wchar_t *, size_t,
102070bc 839 wint_t, int, wint_t *);
96aa2d94 840
2ca8b1ee 841extern struct _IO_FILE_plus *_IO_list_all;
d18ea0c5 842libc_hidden_proto (_IO_list_all)
79937577 843extern void (*_IO_cleanup_registration_needed) (void);
96aa2d94 844
79937577 845extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
9964a145
ZW
846 size_t, char *) __THROW;
847extern off64_t _IO_seekoff_unlocked (FILE *, off64_t, int, int)
0fca3153 848 attribute_hidden;
9964a145 849extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
0fca3153 850 attribute_hidden;
77fe0b9c 851
f8b87ef0
UD
852#if _G_HAVE_MMAP
853
40a55d20
UD
854# include <unistd.h>
855# include <fcntl.h>
856# include <sys/mman.h>
857# include <sys/param.h>
f8b87ef0 858
40a55d20
UD
859# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
860# define MAP_ANONYMOUS MAP_ANON
861# endif
f8b87ef0 862
16c8dfba 863# if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
40a55d20
UD
864# undef _G_HAVE_MMAP
865# define _G_HAVE_MMAP 0
866# endif
f8b87ef0
UD
867
868#endif /* _G_HAVE_MMAP */
869
349718d4
ZW
870/* Flags for __vfscanf_internal and __vfwscanf_internal.
871
872 SCANF_LDBL_IS_DBL indicates whether long double values are to be
873 handled as having the same format as double, in which case the flag
874 should be set to one, or as another format, otherwise.
875
876 SCANF_ISOC99_A, when set to one, indicates that the ISO C99 or POSIX
877 behavior of the scanf functions is to be used, i.e. automatic
878 allocation for input strings with %as, %aS and %a[, a GNU extension,
879 is disabled. This is the behavior that the __isoc99_scanf family of
880 functions use. When the flag is set to zero, automatic allocation is
10446f5d
GG
881 enabled.
882
dee2bea0
JM
883 SCANF_ISOC23_BIN_CST, when set to one, indicates the %i accepts
884 binary constants starting 0b or 0B.
885
10446f5d
GG
886 SCANF_LDBL_USES_FLOAT128 is used on platforms where the long double
887 format used to be different from the IEC 60559 double format *and*
888 also different from the Quadruple 128-bits IEC 60559 format (such as
889 the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
890 format on x86), but was later converted to the Quadruple 128-bits IEC
891 60559 format, which is the same format that the _Float128 always has
892 (hence the `USES_FLOAT128' suffix in the name of the flag). When set
893 to one, this macros indicates that long double values are to be
894 handled as having this new format. Otherwise, they should be handled
895 as the previous format on that platform. */
896#define SCANF_LDBL_IS_DBL 0x0001
897#define SCANF_ISOC99_A 0x0002
dee2bea0
JM
898#define SCANF_ISOC23_BIN_CST 0x0004
899#define SCANF_LDBL_USES_FLOAT128 0x0008
349718d4
ZW
900
901extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
902 unsigned int flags)
903 attribute_hidden;
904extern int __vfwscanf_internal (FILE *fp, const wchar_t *format, va_list argp,
905 unsigned int flags)
906 attribute_hidden;
907
9964a145 908extern int _IO_vscanf (const char *, va_list) __THROW;
96aa2d94 909
499e7464 910#ifdef _IO_MTSAFE_IO
96aa2d94 911/* check following! */
1ddf537f 912# ifdef _IO_USE_OLD_IO_FILE
d64b6ad0 913# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
96aa2d94 914 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
bd0ea9ff 915 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
ae506220
SP
916 NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
917 _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
1ddf537f 918# else
5f0704b6 919# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 920 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
53fcdf5f 921 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
ae506220
SP
922 NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
923 _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, \
924 _IO_pos_BAD, NULL, WDP, NULL }
1ddf537f 925# endif
499e7464 926#else
1ddf537f 927# ifdef _IO_USE_OLD_IO_FILE
b4e3df5d 928# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
499e7464 929 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
bd0ea9ff 930 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
ae506220
SP
931 NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
932 _IO_pos_BAD }
1ddf537f 933# else
5f0704b6 934# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 935 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
bd0ea9ff 936 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
ae506220
SP
937 NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
938 _IO_pos_BAD, 0, 0, { 0 }, NULL, \
939 _IO_pos_BAD, NULL, WDP, NULL }
1ddf537f 940# endif
499e7464 941#endif
96aa2d94 942
a5406364
FW
943#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
944/* See oldstdfiles.c. These are the old stream variables. */
945extern struct _IO_FILE_plus _IO_stdin_;
946extern struct _IO_FILE_plus _IO_stdout_;
947extern struct _IO_FILE_plus _IO_stderr_;
948
949static inline bool
950_IO_legacy_file (FILE *fp)
951{
952 return fp == (FILE *) &_IO_stdin_ || fp == (FILE *) &_IO_stdout_
953 || fp == (FILE *) &_IO_stderr_;
954}
955#endif
956
957/* Deallocate a stream if it is heap-allocated. Preallocated
958 stdin/stdout/stderr streams are not deallocated. */
959static inline void
960_IO_deallocate_file (FILE *fp)
961{
962 /* The current stream variables. */
963 if (fp == (FILE *) &_IO_2_1_stdin_ || fp == (FILE *) &_IO_2_1_stdout_
964 || fp == (FILE *) &_IO_2_1_stderr_)
965 return;
966#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
967 if (_IO_legacy_file (fp))
968 return;
969#endif
970 free (fp);
971}
96aa2d94 972
f65fd747 973#ifdef IO_DEBUG
34a5a146
JM
974# define CHECK_FILE(FILE, RET) do { \
975 if ((FILE) == NULL \
976 || ((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
977 { \
978 __set_errno (EINVAL); \
979 return RET; \
980 } \
30bfee26 981 } while (0)
96aa2d94 982#else
30bfee26 983# define CHECK_FILE(FILE, RET) do { } while (0)
96aa2d94 984#endif
eef80cf8
UD
985
986static inline void
987__attribute__ ((__always_inline__))
9964a145 988_IO_acquire_lock_fct (FILE **p)
eef80cf8 989{
9964a145 990 FILE *fp = *p;
eef80cf8
UD
991 if ((fp->_flags & _IO_USER_LOCK) == 0)
992 _IO_funlockfile (fp);
993}
b257c726 994
4f41c682 995#if !defined _IO_MTSAFE_IO && IS_IN (libc)
b2e1c562 996# define _IO_acquire_lock(_fp) \
4e2f43f8 997 do {
b2e1c562 998# define _IO_release_lock(_fp) \
b2e1c562
RM
999 } while (0)
1000#endif
db3476af 1001
db3476af
FW
1002#ifdef SHARED
1003/* If equal to &_IO_vtable_check (with pointer guard protection),
1004 unknown vtable pointers are valid. This function pointer is solely
1005 used as a flag. */
1006extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
1007
1008/* Assigns the passed function pointer (either NULL or
1009 &_IO_vtable_check) to IO_accept_foreign_vtables. */
1010static inline void
1011IO_set_accept_foreign_vtables (void (*flag) (void))
1012{
1013 PTR_MANGLE (flag);
1014 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
1015}
1016
1017#else /* !SHARED */
1018
1019/* The statically-linked version does nothing. */
1020static inline void
1021IO_set_accept_foreign_vtables (void (*flag) (void))
1022{
1023}
1024
1025#endif
1026
1027/* Check if unknown vtable pointers are permitted; otherwise,
1028 terminate the process. */
1029void _IO_vtable_check (void) attribute_hidden;
1030
1031/* Perform vtable pointer validation. If validation fails, terminate
1032 the process. */
1033static inline const struct _IO_jump_t *
1034IO_validate_vtable (const struct _IO_jump_t *vtable)
1035{
2d1c89a5 1036 uintptr_t ptr = (uintptr_t) vtable;
3020f726
AZN
1037 uintptr_t offset = ptr - (uintptr_t) &__io_vtables;
1038 if (__glibc_unlikely (offset >= IO_VTABLES_LEN))
db3476af
FW
1039 /* The vtable pointer is not in the expected section. Use the
1040 slow path, which will terminate the process if necessary. */
1041 _IO_vtable_check ();
1042 return vtable;
1043}
a4fea3f2 1044
ae506220
SP
1045/* In case of an allocation failure, we resort to using the fixed buffer
1046 _SHORT_BACKUPBUF. Free PTR unless it points to that buffer. */
1047static __always_inline void
1048_IO_free_backup_buf (FILE *fp, char *ptr)
1049{
1050 if (ptr != fp->_short_backupbuf)
1051 free (ptr);
1052}
1053
09e1b0e3
FW
1054/* Character set conversion. */
1055
1056enum __codecvt_result
1057{
1058 __codecvt_ok,
1059 __codecvt_partial,
1060 __codecvt_error,
1061 __codecvt_noconv
1062};
1063
1064enum __codecvt_result __libio_codecvt_out (struct _IO_codecvt *,
1065 __mbstate_t *,
1066 const wchar_t *,
1067 const wchar_t *,
1068 const wchar_t **, char *,
1069 char *, char **)
1070 attribute_hidden;
1071enum __codecvt_result __libio_codecvt_in (struct _IO_codecvt *,
1072 __mbstate_t *,
1073 const char *, const char *,
1074 const char **, wchar_t *,
1075 wchar_t *, wchar_t **)
1076 attribute_hidden;
1077int __libio_codecvt_encoding (struct _IO_codecvt *) attribute_hidden;
1078int __libio_codecvt_length (struct _IO_codecvt *, __mbstate_t *,
1079 const char *, const char *, size_t)
1080 attribute_hidden;
1081
a4fea3f2 1082#endif /* libioP.h. */