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