]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libioP.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / libio / libioP.h
CommitLineData
f7a9f785 1/* Copyright (C) 1993-2016 Free Software Foundation, Inc.
41bdb6e2 2 This file is part of the GNU C Library.
40a55d20 3
41bdb6e2
AJ
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
40a55d20 8
41bdb6e2
AJ
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
40a55d20 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2
AJ
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
41bdb6e2
AJ
17
18 As a special exception, if you link the code in this file with
19 files compiled with a GNU compiler to produce an executable,
20 that does not cause the resulting executable to be covered by
21 the GNU Lesser General Public License. This exception does not
22 however invalidate any other reasons why the executable file
23 might be covered by the GNU Lesser General Public License.
24 This exception applies to code released by its copyright holders
25 in files containing the exception. */
96aa2d94 26
b1848fde
SP
27/* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
28 own implementation. As a result, functions that were implemented for C++
29 (like *sputn) may no longer have C++ semantics. This is of course only
30 relevant for internal callers of these functions since these functions are
31 not intended for external use otherwise.
32
33 FIXME: All of the C++ cruft eventually needs to go away. */
34
e69dcccb
FW
35#include <stddef.h>
36
96aa2d94 37#include <errno.h>
a2b08ee5
UD
38#ifndef __set_errno
39# define __set_errno(Val) errno = (Val)
40#endif
41#if defined __GLIBC__ && __GLIBC__ >= 2
ec999b8e 42# include <libc-lock.h>
a2b08ee5
UD
43#else
44/*# include <comthread.h>*/
45#endif
96aa2d94 46
c6251f03
RM
47#include <math_ldbl_opt.h>
48
96aa2d94
RM
49#include "iolibio.h"
50
77fe0b9c
UD
51/* Control of exported symbols. Used in glibc. By default we don't
52 do anything. */
37ba7d66
UD
53#ifndef libc_hidden_proto
54# define libc_hidden_proto(name)
55#endif
56#ifndef libc_hidden_def
57# define libc_hidden_def(name)
58#endif
59#ifndef libc_hidden_weak
60# define libc_hidden_weak(name)
61#endif
62
4547c1a4
UD
63#ifdef __cplusplus
64extern "C" {
65#endif
96aa2d94
RM
66
67#define _IO_seek_set 0
68#define _IO_seek_cur 1
69#define _IO_seek_end 2
70
f65fd747
UD
71/* THE JUMPTABLE FUNCTIONS.
72
73 * The _IO_FILE type is used to implement the FILE type in GNU libc,
74 * as well as the streambuf class in GNU iostreams for C++.
75 * These are all the same, just used differently.
76 * An _IO_FILE (or FILE) object is allows followed by a pointer to
77 * a jump table (of pointers to functions). The pointer is accessed
c0c3f78a 78 * with the _IO_JUMPS macro. The jump table has an eccentric format,
f65fd747 79 * so as to be compatible with the layout of a C++ virtual function table.
6d52618b 80 * (as implemented by g++). When a pointer to a streambuf object is
f65fd747
UD
81 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
82 * happens to point to the virtual function table of the streambuf.
83 * Thus the _IO_JUMPS function table used for C stdio/libio does
6d52618b 84 * double duty as the virtual function table for C++ streambuf.
f65fd747
UD
85 *
86 * The entries in the _IO_JUMPS function table (and hence also the
87 * virtual functions of a streambuf) are described below.
88 * The first parameter of each function entry is the _IO_FILE/streambuf
89 * object being acted on (i.e. the 'this' parameter).
90 */
96aa2d94 91
00404a96
RM
92#ifdef _LIBC
93# include <shlib-compat.h>
94# if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
95 /* Setting this macro disables the use of the _vtable_offset
96 bias in _IO_JUMPS_FUNCS, below. That is only needed if we
97 want to support old binaries (see oldfileops.c). */
98# define _G_IO_NO_BACKWARD_COMPAT 1
99# endif
100#endif
101
bd355af0
UD
102#if (!defined _IO_USE_OLD_IO_FILE \
103 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
104# define _IO_JUMPS_OFFSET 1
8f2f08d0
RM
105#else
106# define _IO_JUMPS_OFFSET 0
bd355af0
UD
107#endif
108
e69dcccb
FW
109/* Type of MEMBER in struct type TYPE. */
110#define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
111
112/* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
113 violation in case THIS has a different pointer type. */
114#define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
115 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
7348824c 116 + offsetof(TYPE, MEMBER)))
e69dcccb 117
2ca8b1ee 118#define _IO_JUMPS(THIS) (THIS)->vtable
e69dcccb
FW
119#define _IO_JUMPS_FILE_plus(THIS) \
120 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
121#define _IO_WIDE_JUMPS(THIS) \
122 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
123#define _IO_CHECK_WIDE(THIS) \
124 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
7163e69e 125
c15cf13a 126#if _IO_JUMPS_OFFSET
bd355af0 127# define _IO_JUMPS_FUNC(THIS) \
e69dcccb 128 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
bd355af0 129 + (THIS)->_vtable_offset))
bbdef797 130# define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
bd355af0 131#else
e69dcccb 132# define _IO_JUMPS_FUNC(THIS) _IO_JUMPS_FILE_plus (THIS)
bbdef797 133# define _IO_vtable_offset(THIS) 0
bd355af0 134#endif
6e06ae59 135#define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
28361c5e
JM
136#define JUMP_FIELD(TYPE, NAME) TYPE NAME
137#define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
138#define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
139#define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
140#define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
141#define JUMP_INIT(NAME, VALUE) VALUE
142#define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
143
144#define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
145#define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
146#define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
147#define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
96aa2d94 148
f65fd747 149/* The 'finish' function does any final cleaning up of an _IO_FILE object.
110215a9 150 It does not delete (free) it, but does everything else to finalize it.
f65fd747 151 It matches the streambuf::~streambuf virtual destructor. */
79937577 152typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
40a55d20 153#define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
6e06ae59 154#define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
f65fd747
UD
155
156/* The 'overflow' hook flushes the buffer.
157 The second argument is a character, or EOF.
158 It matches the streambuf::overflow virtual function. */
79937577 159typedef int (*_IO_overflow_t) (_IO_FILE *, int);
40a55d20 160#define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
6e06ae59 161#define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
f65fd747
UD
162
163/* The 'underflow' hook tries to fills the get buffer.
164 It returns the next character (as an unsigned char) or EOF. The next
6d52618b 165 character remains in the get buffer, and the get position is not changed.
f65fd747 166 It matches the streambuf::underflow virtual function. */
79937577 167typedef int (*_IO_underflow_t) (_IO_FILE *);
40a55d20 168#define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
6e06ae59 169#define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
f65fd747
UD
170
171/* The 'uflow' hook returns the next character in the input stream
172 (cast to unsigned char), and increments the read position;
173 EOF is returned on failure.
174 It matches the streambuf::uflow virtual function, which is not in the
175 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
40a55d20 176#define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
6e06ae59 177#define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
f65fd747
UD
178
179/* The 'pbackfail' hook handles backing up.
180 It matches the streambuf::pbackfail virtual function. */
79937577 181typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
40a55d20 182#define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
6e06ae59 183#define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
f65fd747
UD
184
185/* The 'xsputn' hook writes upto N characters from buffer DATA.
2b766585 186 Returns EOF or the number of character actually written.
f65fd747 187 It matches the streambuf::xsputn virtual function. */
79937577
UD
188typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
189 _IO_size_t N);
40a55d20 190#define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
6e06ae59 191#define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
f65fd747
UD
192
193/* The 'xsgetn' hook reads upto N characters into buffer DATA.
194 Returns the number of character actually read.
195 It matches the streambuf::xsgetn virtual function. */
79937577 196typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
40a55d20 197#define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
6e06ae59 198#define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
f65fd747
UD
199
200/* The 'seekoff' hook moves the stream position to a new position
201 relative to the start of the file (if DIR==0), the current position
202 (MODE==1), or the end of the file (MODE==2).
203 It matches the streambuf::seekoff virtual function.
204 It is also used for the ANSI fseek function. */
79937577
UD
205typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
206 int MODE);
40a55d20 207#define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
6e06ae59 208#define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
f65fd747
UD
209
210/* The 'seekpos' hook also moves the stream position,
dfd2257a 211 but to an absolute position given by a fpos64_t (seekpos).
f65fd747
UD
212 It matches the streambuf::seekpos virtual function.
213 It is also used for the ANSI fgetpos and fsetpos functions. */
214/* The _IO_seek_cur and _IO_seek_end options are not allowed. */
79937577 215typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
40a55d20 216#define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
6e06ae59 217#define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
f65fd747
UD
218
219/* The 'setbuf' hook gives a buffer to the file.
220 It matches the streambuf::setbuf virtual function. */
79937577 221typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
40a55d20 222#define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
6e06ae59 223#define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
f65fd747
UD
224
225/* The 'sync' hook attempts to synchronize the internal data structures
226 of the file with the external state.
227 It matches the streambuf::sync virtual function. */
79937577 228typedef int (*_IO_sync_t) (_IO_FILE *);
40a55d20 229#define _IO_SYNC(FP) JUMP0 (__sync, FP)
6e06ae59 230#define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
f65fd747
UD
231
232/* The 'doallocate' hook is used to tell the file to allocate a buffer.
233 It matches the streambuf::doallocate virtual function, which is not
234 in the ANSI/ISO C++ standard, but is part traditional implementations. */
79937577 235typedef int (*_IO_doallocate_t) (_IO_FILE *);
40a55d20 236#define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
6e06ae59 237#define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
f65fd747
UD
238
239/* The following four hooks (sysread, syswrite, sysclose, sysseek, and
240 sysstat) are low-level hooks specific to this implementation.
6d52618b 241 There is no correspondence in the ANSI/ISO C++ standard library.
f65fd747
UD
242 The hooks basically correspond to the Unix system functions
243 (read, write, close, lseek, and stat) except that a _IO_FILE*
c0c3f78a 244 parameter is used instead of an integer file descriptor; the default
f65fd747
UD
245 implementation used for normal files just calls those functions.
246 The advantage of overriding these functions instead of the higher-level
247 ones (underflow, overflow etc) is that you can leave all the buffering
248 higher-level functions. */
249
250/* The 'sysread' hook is used to read data from the external file into
251 an existing buffer. It generalizes the Unix read(2) function.
252 It matches the streambuf::sys_read virtual function, which is
6d52618b 253 specific to this implementation. */
79937577 254typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
40a55d20 255#define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
6e06ae59 256#define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
f65fd747
UD
257
258/* The 'syswrite' hook is used to write data from an existing buffer
259 to an external file. It generalizes the Unix write(2) function.
260 It matches the streambuf::sys_write virtual function, which is
6d52618b 261 specific to this implementation. */
79937577 262typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
40a55d20 263#define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
6e06ae59 264#define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
f65fd747
UD
265
266/* The 'sysseek' hook is used to re-position an external file.
267 It generalizes the Unix lseek(2) function.
268 It matches the streambuf::sys_seek virtual function, which is
6d52618b 269 specific to this implementation. */
79937577 270typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
40a55d20 271#define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
6e06ae59 272#define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
f65fd747
UD
273
274/* The 'sysclose' hook is used to finalize (close, finish up) an
275 external file. It generalizes the Unix close(2) function.
276 It matches the streambuf::sys_close virtual function, which is
277 specific to this implementation. */
79937577 278typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
40a55d20 279#define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
6e06ae59 280#define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
f65fd747
UD
281
282/* The 'sysstat' hook is used to get information about an external file
283 into a struct stat buffer. It generalizes the Unix fstat(2) call.
284 It matches the streambuf::sys_stat virtual function, which is
6d52618b 285 specific to this implementation. */
79937577 286typedef int (*_IO_stat_t) (_IO_FILE *, void *);
40a55d20 287#define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
6e06ae59 288#define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
96aa2d94 289
dfd2257a
UD
290/* The 'showmany' hook can be used to get an image how much input is
291 available. In many cases the answer will be 0 which means unknown
292 but some cases one can provide real information. */
79937577 293typedef int (*_IO_showmanyc_t) (_IO_FILE *);
dfd2257a 294#define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
6e06ae59 295#define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
dfd2257a
UD
296
297/* The 'imbue' hook is used to get information about the currently
298 installed locales. */
79937577 299typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
dfd2257a 300#define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
6e06ae59 301#define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
dfd2257a 302
f65fd747 303
96aa2d94
RM
304#define _IO_CHAR_TYPE char /* unsigned char ? */
305#define _IO_INT_TYPE int
306
40a55d20
UD
307struct _IO_jump_t
308{
203e5603
JM
309 JUMP_FIELD(size_t, __dummy);
310 JUMP_FIELD(size_t, __dummy2);
96aa2d94
RM
311 JUMP_FIELD(_IO_finish_t, __finish);
312 JUMP_FIELD(_IO_overflow_t, __overflow);
313 JUMP_FIELD(_IO_underflow_t, __underflow);
314 JUMP_FIELD(_IO_underflow_t, __uflow);
315 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
316 /* showmany */
317 JUMP_FIELD(_IO_xsputn_t, __xsputn);
318 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
319 JUMP_FIELD(_IO_seekoff_t, __seekoff);
320 JUMP_FIELD(_IO_seekpos_t, __seekpos);
321 JUMP_FIELD(_IO_setbuf_t, __setbuf);
322 JUMP_FIELD(_IO_sync_t, __sync);
323 JUMP_FIELD(_IO_doallocate_t, __doallocate);
324 JUMP_FIELD(_IO_read_t, __read);
325 JUMP_FIELD(_IO_write_t, __write);
326 JUMP_FIELD(_IO_seek_t, __seek);
327 JUMP_FIELD(_IO_close_t, __close);
328 JUMP_FIELD(_IO_stat_t, __stat);
dfd2257a
UD
329 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
330 JUMP_FIELD(_IO_imbue_t, __imbue);
96aa2d94
RM
331#if 0
332 get_column;
333 set_column;
334#endif
335};
336
337/* We always allocate an extra word following an _IO_FILE.
f65fd747 338 This contains a pointer to the function jump table used.
96aa2d94
RM
339 This is for compatibility with C++ streambuf; the word can
340 be used to smash to a pointer to a virtual function table. */
341
40a55d20
UD
342struct _IO_FILE_plus
343{
96aa2d94 344 _IO_FILE file;
96aa2d94 345 const struct _IO_jump_t *vtable;
96aa2d94
RM
346};
347
7ea11363
UD
348#ifdef _IO_USE_OLD_IO_FILE
349/* This structure is used by the compatibility code as if it were an
350 _IO_FILE_plus, but has enough space to initialize the _mode argument
351 of an _IO_FILE_complete. */
352struct _IO_FILE_complete_plus
353{
354 struct _IO_FILE_complete file;
355 const struct _IO_jump_t *vtable;
356};
357#endif
358
2ca8b1ee
GM
359/* Special file type for fopencookie function. */
360struct _IO_cookie_file
361{
362 struct _IO_FILE_plus __fp;
363 void *__cookie;
364 _IO_cookie_io_functions_t __io_functions;
365};
366
c9fc9559
RM
367_IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
368 _IO_cookie_io_functions_t io_functions);
369
370
3fc9ca4e
UD
371/* Iterator type for walking global linked list of _IO_FILE objects. */
372
73c115ed 373typedef struct _IO_FILE *_IO_ITER;
3fc9ca4e 374
96aa2d94
RM
375/* Generic functions */
376
79937577
UD
377extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
378extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
0fca3153 379extern int _IO_switch_to_get_mode (_IO_FILE *);
d18ea0c5 380libc_hidden_proto (_IO_switch_to_get_mode)
79937577 381extern void _IO_init (_IO_FILE *, int) __THROW;
d18ea0c5 382libc_hidden_proto (_IO_init)
79937577 383extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
d18ea0c5 384libc_hidden_proto (_IO_sputbackc)
79937577
UD
385extern int _IO_sungetc (_IO_FILE *) __THROW;
386extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
d18ea0c5 387libc_hidden_proto (_IO_un_link)
79937577 388extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
d18ea0c5 389libc_hidden_proto (_IO_link_in)
79937577 390extern void _IO_doallocbuf (_IO_FILE *) __THROW;
d18ea0c5 391libc_hidden_proto (_IO_doallocbuf)
79937577 392extern void _IO_unsave_markers (_IO_FILE *) __THROW;
d18ea0c5 393libc_hidden_proto (_IO_unsave_markers)
79937577 394extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
d18ea0c5 395libc_hidden_proto (_IO_setb)
79937577 396extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
d18ea0c5 397libc_hidden_proto (_IO_adjust_column)
40a55d20 398#define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
96aa2d94 399
d18ea0c5
AS
400_IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
401libc_hidden_proto (_IO_least_wmarker)
79937577 402extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
d18ea0c5 403libc_hidden_proto (_IO_switch_to_main_wget_area)
79937577 404extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
d18ea0c5 405libc_hidden_proto (_IO_switch_to_wbackup_area)
0fca3153 406extern int _IO_switch_to_wget_mode (_IO_FILE *);
d18ea0c5 407libc_hidden_proto (_IO_switch_to_wget_mode)
79937577 408extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
d18ea0c5 409libc_hidden_proto (_IO_wsetb)
79937577 410extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
d18ea0c5 411libc_hidden_proto (_IO_sputbackwc)
79937577
UD
412extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
413extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
d18ea0c5 414libc_hidden_proto (_IO_wdoallocbuf)
79937577
UD
415extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
416extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
000232b9 417extern _IO_off64_t get_file_offset (_IO_FILE *fp);
d64b6ad0 418
96aa2d94
RM
419/* Marker-related function. */
420
0fca3153
UD
421extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
422extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
79937577
UD
423extern void _IO_remove_marker (struct _IO_marker *) __THROW;
424extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
425 __THROW;
426extern int _IO_marker_delta (struct _IO_marker *) __THROW;
427extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
428extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
429extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
96aa2d94 430
79937577 431/* Functions for iterating global list and dealing with its lock */
3fc9ca4e 432
79937577 433extern _IO_ITER _IO_iter_begin (void) __THROW;
1d2b6e0c 434libc_hidden_proto (_IO_iter_begin)
79937577 435extern _IO_ITER _IO_iter_end (void) __THROW;
1d2b6e0c 436libc_hidden_proto (_IO_iter_end)
79937577 437extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
1d2b6e0c 438libc_hidden_proto (_IO_iter_next)
79937577 439extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
1d2b6e0c 440libc_hidden_proto (_IO_iter_file)
79937577 441extern void _IO_list_lock (void) __THROW;
245eab02 442libc_hidden_proto (_IO_list_lock)
79937577 443extern void _IO_list_unlock (void) __THROW;
245eab02 444libc_hidden_proto (_IO_list_unlock)
79937577 445extern void _IO_list_resetlock (void) __THROW;
245eab02 446libc_hidden_proto (_IO_list_resetlock)
3fc9ca4e 447
96aa2d94
RM
448/* Default jumptable functions. */
449
79937577 450extern int _IO_default_underflow (_IO_FILE *) __THROW;
0fca3153 451extern int _IO_default_uflow (_IO_FILE *);
d18ea0c5 452libc_hidden_proto (_IO_default_uflow)
0fca3153 453extern wint_t _IO_wdefault_uflow (_IO_FILE *);
d18ea0c5 454libc_hidden_proto (_IO_wdefault_uflow)
79937577 455extern int _IO_default_doallocate (_IO_FILE *) __THROW;
d18ea0c5 456libc_hidden_proto (_IO_default_doallocate)
79937577 457extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
d18ea0c5 458libc_hidden_proto (_IO_wdefault_doallocate)
79937577 459extern void _IO_default_finish (_IO_FILE *, int) __THROW;
d18ea0c5 460libc_hidden_proto (_IO_default_finish)
79937577 461extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
d18ea0c5 462libc_hidden_proto (_IO_wdefault_finish)
79937577 463extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
d18ea0c5 464libc_hidden_proto (_IO_default_pbackfail)
79937577 465extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
d18ea0c5 466libc_hidden_proto (_IO_wdefault_pbackfail)
0fca3153 467extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
102070bc 468extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 469libc_hidden_proto (_IO_default_xsputn)
102070bc 470extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 471libc_hidden_proto (_IO_wdefault_xsputn)
102070bc 472extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 473libc_hidden_proto (_IO_default_xsgetn)
102070bc 474extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 475libc_hidden_proto (_IO_wdefault_xsgetn)
79937577
UD
476extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
477 __THROW;
0fca3153 478extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
102070bc
UD
479extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
480extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
79937577
UD
481extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
482extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
483extern int _IO_default_sync (_IO_FILE *) __THROW;
40a55d20 484#define _IO_default_close ((_IO_close_t) _IO_default_sync)
79937577
UD
485extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
486extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
96aa2d94 487
b2637a22 488extern const struct _IO_jump_t _IO_file_jumps;
15a686af 489libc_hidden_proto (_IO_file_jumps)
b2637a22
UD
490extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
491extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
492extern const struct _IO_jump_t _IO_wfile_jumps;
15a686af 493libc_hidden_proto (_IO_wfile_jumps)
b2637a22
UD
494extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
495extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
496extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
497extern const struct _IO_jump_t _IO_streambuf_jumps;
498extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
499extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
500extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
97d261ad 501extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
0fca3153 502extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
d18ea0c5 503libc_hidden_proto (_IO_do_write)
0fca3153
UD
504extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
505extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
506extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
d18ea0c5 507libc_hidden_proto (_IO_wdo_write)
0fca3153
UD
508extern int _IO_flush_all_lockp (int);
509extern int _IO_flush_all (void);
d18ea0c5 510libc_hidden_proto (_IO_flush_all)
0fca3153
UD
511extern int _IO_cleanup (void);
512extern void _IO_flush_all_linebuffered (void);
d18ea0c5 513libc_hidden_proto (_IO_flush_all_linebuffered)
0fca3153
UD
514extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
515extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
516extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
517extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
518extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
519extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
520extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
521extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
79937577 522extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
d64b6ad0 523
96aa2d94 524
319d719d
UD
525#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
526# define _IO_do_flush(_f) \
d64b6ad0 527 ((_f)->_mode <= 0 \
d18ea0c5
AS
528 ? _IO_do_write(_f, (_f)->_IO_write_base, \
529 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
530 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
531 ((_f)->_wide_data->_IO_write_ptr \
532 - (_f)->_wide_data->_IO_write_base)))
319d719d
UD
533#else
534# define _IO_do_flush(_f) \
d18ea0c5
AS
535 _IO_do_write(_f, (_f)->_IO_write_base, \
536 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
319d719d 537#endif
6973fc01
UD
538#define _IO_old_do_flush(_f) \
539 _IO_old_do_write(_f, (_f)->_IO_write_base, \
540 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
96aa2d94
RM
541#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
542#define _IO_mask_flags(fp, f, mask) \
543 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
544#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
545 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
d64b6ad0
UD
546#define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
547 (fp)->_wide_data->_IO_read_ptr = (g), \
548 (fp)->_wide_data->_IO_read_end = (eg))
96aa2d94 549#define _IO_setp(__fp, __p, __ep) \
d64b6ad0
UD
550 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
551 = __p, (__fp)->_IO_write_end = (__ep))
552#define _IO_wsetp(__fp, __p, __ep) \
553 ((__fp)->_wide_data->_IO_write_base \
554 = (__fp)->_wide_data->_IO_write_ptr = __p, \
555 (__fp)->_wide_data->_IO_write_end = (__ep))
96aa2d94 556#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
d64b6ad0 557#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
96aa2d94
RM
558#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
559#define _IO_have_markers(fp) ((fp)->_markers != NULL)
f65fd747 560#define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
d64b6ad0
UD
561#define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
562 - (fp)->_wide_data->_IO_buf_base)
96aa2d94
RM
563
564/* Jumptable functions for files. */
565
79937577 566extern int _IO_file_doallocate (_IO_FILE *) __THROW;
d18ea0c5 567libc_hidden_proto (_IO_file_doallocate)
0fca3153 568extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
d18ea0c5 569libc_hidden_proto (_IO_file_setbuf)
0fca3153 570extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
d18ea0c5 571libc_hidden_proto (_IO_file_seekoff)
79937577
UD
572extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
573 __THROW;
0fca3153 574extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 575libc_hidden_proto (_IO_file_xsputn)
0fca3153 576extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 577libc_hidden_proto (_IO_file_xsgetn)
79937577 578extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
d18ea0c5 579libc_hidden_proto (_IO_file_stat)
79937577 580extern int _IO_file_close (_IO_FILE *) __THROW;
d18ea0c5 581libc_hidden_proto (_IO_file_close)
79937577 582extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
0fca3153 583extern int _IO_file_underflow (_IO_FILE *);
d18ea0c5 584libc_hidden_proto (_IO_file_underflow)
0fca3153
UD
585extern int _IO_file_underflow_mmap (_IO_FILE *);
586extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
587extern int _IO_file_overflow (_IO_FILE *, int);
d18ea0c5 588libc_hidden_proto (_IO_file_overflow)
110215a9 589#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
79937577 590extern void _IO_file_init (struct _IO_FILE_plus *) __THROW;
d18ea0c5 591libc_hidden_proto (_IO_file_init)
0fca3153 592extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
d18ea0c5 593libc_hidden_proto (_IO_file_attach)
0fca3153 594extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
ee2a5ae8 595libc_hidden_proto (_IO_file_open)
0fca3153 596extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
d18ea0c5 597libc_hidden_proto (_IO_file_fopen)
0fca3153
UD
598extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
599extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
d18ea0c5 600libc_hidden_proto (_IO_file_read)
0fca3153 601extern int _IO_file_sync (_IO_FILE *);
d18ea0c5 602libc_hidden_proto (_IO_file_sync)
0fca3153 603extern int _IO_file_close_it (_IO_FILE *);
d18ea0c5 604libc_hidden_proto (_IO_file_close_it)
79937577 605extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
d18ea0c5 606libc_hidden_proto (_IO_file_seek)
0fca3153 607extern void _IO_file_finish (_IO_FILE *, int);
d18ea0c5 608libc_hidden_proto (_IO_file_finish)
79937577 609
0fca3153
UD
610extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
611extern int _IO_new_file_close_it (_IO_FILE *);
612extern void _IO_new_file_finish (_IO_FILE *, int);
79937577 613extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
0fca3153 614 int);
79937577
UD
615extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
616 const struct _IO_jump_t *) __THROW;
617extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW;
0fca3153
UD
618extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
619extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
620extern int _IO_new_file_sync (_IO_FILE *);
621extern int _IO_new_file_underflow (_IO_FILE *);
622extern int _IO_new_file_overflow (_IO_FILE *, int);
623extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
624extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
625extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
626
627extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
628extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
629extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
630extern int _IO_old_file_underflow (_IO_FILE *);
631extern int _IO_old_file_overflow (_IO_FILE *, int);
79937577 632extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW;
0fca3153
UD
633extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
634extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
635extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
636extern int _IO_old_file_sync (_IO_FILE *);
637extern int _IO_old_file_close_it (_IO_FILE *);
638extern void _IO_old_file_finish (_IO_FILE *, int);
79937577
UD
639
640extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
0fca3153 641extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 642libc_hidden_proto (_IO_wfile_xsputn)
0fca3153
UD
643extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
644extern wint_t _IO_wfile_sync (_IO_FILE *);
d18ea0c5 645libc_hidden_proto (_IO_wfile_sync)
0fca3153 646extern wint_t _IO_wfile_underflow (_IO_FILE *);
d18ea0c5 647libc_hidden_proto (_IO_wfile_underflow)
0fca3153 648extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
d18ea0c5 649libc_hidden_proto (_IO_wfile_overflow)
0fca3153 650extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
d18ea0c5 651libc_hidden_proto (_IO_wfile_seekoff)
d64b6ad0 652
96aa2d94 653/* Jumptable functions for proc_files. */
79937577
UD
654extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
655 __THROW;
656extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
657 __THROW;
0fca3153 658extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
79937577
UD
659extern int _IO_proc_close (_IO_FILE *) __THROW;
660extern int _IO_new_proc_close (_IO_FILE *) __THROW;
0fca3153 661extern int _IO_old_proc_close (_IO_FILE *);
96aa2d94
RM
662
663/* Jumptable functions for strfiles. */
79937577 664extern int _IO_str_underflow (_IO_FILE *) __THROW;
d18ea0c5 665libc_hidden_proto (_IO_str_underflow)
79937577 666extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
d18ea0c5 667libc_hidden_proto (_IO_str_overflow)
79937577 668extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
d18ea0c5 669libc_hidden_proto (_IO_str_pbackfail)
79937577 670extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
d18ea0c5 671libc_hidden_proto (_IO_str_seekoff)
79937577 672extern void _IO_str_finish (_IO_FILE *, int) __THROW;
96aa2d94
RM
673
674/* Other strfile functions */
2ca8b1ee 675struct _IO_strfile_;
79937577
UD
676extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *)
677 __THROW;
678extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int)
679 __THROW;
680extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
96aa2d94 681
d64b6ad0 682/* And the wide character versions. */
79937577
UD
683extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
684 __THROW;
685extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
686extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
687extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
688extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
689 __THROW;
690extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
691extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
692
a784e502 693extern int _IO_vasprintf (char **result_ptr, const char *format,
79937577 694 _IO_va_list args) __THROW;
a784e502 695extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
79937577 696extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
a784e502 697 const char *format, _IO_va_list args) __THROW;
79937577
UD
698
699
102070bc 700extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
d18ea0c5 701libc_hidden_proto (_IO_getline)
79937577 702extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
102070bc 703 int, int, int *);
d18ea0c5 704libc_hidden_proto (_IO_getline_info)
0fca3153 705extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
102070bc 706extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
79937577 707extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
102070bc 708 wint_t, int, wint_t *);
96aa2d94 709
2ca8b1ee 710extern struct _IO_FILE_plus *_IO_list_all;
d18ea0c5 711libc_hidden_proto (_IO_list_all)
79937577 712extern void (*_IO_cleanup_registration_needed) (void);
96aa2d94 713
79937577
UD
714extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
715 _IO_size_t, char *) __THROW;
52a16e58 716extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
0fca3153 717 attribute_hidden;
52a16e58 718extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
0fca3153 719 attribute_hidden;
77fe0b9c 720
96aa2d94 721#ifndef EOF
40a55d20 722# define EOF (-1)
96aa2d94
RM
723#endif
724#ifndef NULL
40a55d20 725# if defined __GNUG__ && \
f8b87ef0 726 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
40a55d20
UD
727# define NULL (__null)
728# else
729# if !defined(__cplusplus)
730# define NULL ((void*)0)
731# else
732# define NULL (0)
733# endif
734# endif
f65fd747 735#endif
96aa2d94 736
f8b87ef0
UD
737#if _G_HAVE_MMAP
738
40a55d20
UD
739# include <unistd.h>
740# include <fcntl.h>
741# include <sys/mman.h>
742# include <sys/param.h>
f8b87ef0 743
40a55d20
UD
744# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
745# define MAP_ANONYMOUS MAP_ANON
746# endif
f8b87ef0 747
40a55d20
UD
748# if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
749# undef _G_HAVE_MMAP
750# define _G_HAVE_MMAP 0
751# endif
f8b87ef0
UD
752
753#endif /* _G_HAVE_MMAP */
754
755#if _G_HAVE_MMAP
756
40a55d20 757# ifdef _LIBC
10dc2a90 758/* When using this code in the GNU libc we must not pollute the name space. */
40a55d20
UD
759# define mmap __mmap
760# define munmap __munmap
dfd2257a 761# define ftruncate __ftruncate
40a55d20 762# endif
f8b87ef0 763#endif /* _G_HAVE_MMAP */
96aa2d94
RM
764
765#ifndef OS_FSTAT
40a55d20 766# define OS_FSTAT fstat
96aa2d94 767#endif
79937577 768extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
96aa2d94 769
d64b6ad0 770/* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
96aa2d94 771#ifndef _IO_pos_BAD
d64b6ad0 772# define _IO_pos_BAD ((_IO_off64_t) -1)
96aa2d94 773#endif
d64b6ad0 774/* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
96aa2d94 775#ifndef _IO_pos_adjust
d64b6ad0 776# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
96aa2d94 777#endif
d64b6ad0 778/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
96aa2d94 779#ifndef _IO_pos_0
d64b6ad0 780# define _IO_pos_0 ((_IO_off64_t) 0)
96aa2d94
RM
781#endif
782
4547c1a4
UD
783#ifdef __cplusplus
784}
785#endif
96aa2d94 786
499e7464 787#ifdef _IO_MTSAFE_IO
96aa2d94 788/* check following! */
1ddf537f 789# ifdef _IO_USE_OLD_IO_FILE
d64b6ad0 790# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
96aa2d94 791 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 792 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
73c115ed 793 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
1ddf537f 794# else
319d719d
UD
795# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
796# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 797 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 798 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
d64b6ad0
UD
799 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
800 NULL, WDP, 0 }
319d719d
UD
801# else
802# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
803 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
804 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
805 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
806 0 }
807# endif
1ddf537f 808# endif
499e7464 809#else
1ddf537f 810# ifdef _IO_USE_OLD_IO_FILE
b4e3df5d 811# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
499e7464 812 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
73c115ed
GM
813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
814 0, _IO_pos_BAD }
1ddf537f 815# else
319d719d
UD
816# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
817# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 818 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 819 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
d64b6ad0
UD
820 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
821 NULL, WDP, 0 }
319d719d
UD
822# else
823# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
824 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
825 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
826 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
827 0 }
828# endif
1ddf537f 829# endif
499e7464 830#endif
96aa2d94 831
965a54a4 832#define _IO_va_start(args, last) va_start(args, last)
96aa2d94
RM
833
834extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
835
836#if 1
40a55d20 837# define COERCE_FILE(FILE) /* Nothing */
96aa2d94
RM
838#else
839/* This is part of the kludge for binary compatibility with old stdio. */
40a55d20 840# define COERCE_FILE(FILE) \
96aa2d94
RM
841 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
842 && (FILE) = *(FILE**)&((int*)fp)[1])
843#endif
844
845#ifdef EINVAL
40a55d20 846# define MAYBE_SET_EINVAL __set_errno (EINVAL)
96aa2d94 847#else
40a55d20 848# define MAYBE_SET_EINVAL /* nothing */
96aa2d94
RM
849#endif
850
f65fd747 851#ifdef IO_DEBUG
40a55d20 852# define CHECK_FILE(FILE, RET) \
96aa2d94
RM
853 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
854 else { COERCE_FILE(FILE); \
855 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
68dbb3a6 856 { MAYBE_SET_EINVAL; return RET; }}
96aa2d94 857#else
40a55d20 858# define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
96aa2d94 859#endif
eef80cf8
UD
860
861static inline void
862__attribute__ ((__always_inline__))
863_IO_acquire_lock_fct (_IO_FILE **p)
864{
865 _IO_FILE *fp = *p;
866 if ((fp->_flags & _IO_USER_LOCK) == 0)
867 _IO_funlockfile (fp);
868}
b257c726
UD
869
870static inline void
871__attribute__ ((__always_inline__))
872_IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
873{
874 _IO_FILE *fp = *p;
874aa523 875 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
b257c726
UD
876 if ((fp->_flags & _IO_USER_LOCK) == 0)
877 _IO_funlockfile (fp);
878}
b2e1c562 879
4f41c682 880#if !defined _IO_MTSAFE_IO && IS_IN (libc)
b2e1c562
RM
881# define _IO_acquire_lock(_fp) \
882 do { \
883 _IO_FILE *_IO_acquire_lock_file = NULL
884# define _IO_acquire_lock_clear_flags2(_fp) \
885 do { \
886 _IO_FILE *_IO_acquire_lock_file = (_fp)
887# define _IO_release_lock(_fp) \
888 if (_IO_acquire_lock_file != NULL) \
889 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
890 | _IO_FLAGS2_SCANF_STD); \
891 } while (0)
892#endif