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