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