modernc.org/cc@v1.0.1/v2/headers/linux_amd64/usr/include/libio.h (about) 1 /* Copyright (C) 1991-2015 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 Written by Per Bothner <bothner@cygnus.com>. 4 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. 9 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, see 17 <http://www.gnu.org/licenses/>. 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. */ 27 28 #ifndef _IO_STDIO_H 29 #define _IO_STDIO_H 30 31 #include <_G_config.h> 32 /* ALL of these should be defined in _G_config.h */ 33 #define _IO_fpos_t _G_fpos_t 34 #define _IO_fpos64_t _G_fpos64_t 35 #define _IO_size_t size_t 36 #define _IO_ssize_t __ssize_t 37 #define _IO_off_t __off_t 38 #define _IO_off64_t __off64_t 39 #define _IO_pid_t __pid_t 40 #define _IO_uid_t __uid_t 41 #define _IO_iconv_t _G_iconv_t 42 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE 43 #define _IO_BUFSIZ _G_BUFSIZ 44 #define _IO_va_list _G_va_list 45 #define _IO_wint_t wint_t 46 47 /* This define avoids name pollution if we're using GNU stdarg.h */ 48 #define __need___va_list 49 #include <stdarg.h> 50 #ifdef __GNUC_VA_LIST 51 # undef _IO_va_list 52 # define _IO_va_list __gnuc_va_list 53 #endif /* __GNUC_VA_LIST */ 54 55 #ifndef __P 56 # include <sys/cdefs.h> 57 #endif /*!__P */ 58 59 #define _IO_UNIFIED_JUMPTABLES 1 60 61 #ifndef EOF 62 # define EOF (-1) 63 #endif 64 #ifndef NULL 65 # if defined __GNUG__ && \ 66 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) 67 # define NULL (__null) 68 # else 69 # if !defined(__cplusplus) 70 # define NULL ((void*)0) 71 # else 72 # define NULL (0) 73 # endif 74 # endif 75 #endif 76 77 #define _IOS_INPUT 1 78 #define _IOS_OUTPUT 2 79 #define _IOS_ATEND 4 80 #define _IOS_APPEND 8 81 #define _IOS_TRUNC 16 82 #define _IOS_NOCREATE 32 83 #define _IOS_NOREPLACE 64 84 #define _IOS_BIN 128 85 86 /* Magic numbers and bits for the _flags field. 87 The magic numbers use the high-order bits of _flags; 88 the remaining bits are available for variable flags. 89 Note: The magic numbers must all be negative if stdio 90 emulation is desired. */ 91 92 #define _IO_MAGIC 0xFBAD0000 /* Magic number */ 93 #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */ 94 #define _IO_MAGIC_MASK 0xFFFF0000 95 #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */ 96 #define _IO_UNBUFFERED 2 97 #define _IO_NO_READS 4 /* Reading not allowed */ 98 #define _IO_NO_WRITES 8 /* Writing not allowd */ 99 #define _IO_EOF_SEEN 0x10 100 #define _IO_ERR_SEEN 0x20 101 #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */ 102 #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all. */ 103 #define _IO_IN_BACKUP 0x100 104 #define _IO_LINE_BUF 0x200 105 #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */ 106 #define _IO_CURRENTLY_PUTTING 0x800 107 #define _IO_IS_APPENDING 0x1000 108 #define _IO_IS_FILEBUF 0x2000 109 #define _IO_BAD_SEEN 0x4000 110 #define _IO_USER_LOCK 0x8000 111 112 #define _IO_FLAGS2_MMAP 1 113 #define _IO_FLAGS2_NOTCANCEL 2 114 #ifdef _LIBC 115 # define _IO_FLAGS2_FORTIFY 4 116 #endif 117 #define _IO_FLAGS2_USER_WBUF 8 118 #ifdef _LIBC 119 # define _IO_FLAGS2_SCANF_STD 16 120 # define _IO_FLAGS2_NOCLOSE 32 121 # define _IO_FLAGS2_CLOEXEC 64 122 #endif 123 124 /* These are "formatting flags" matching the iostream fmtflags enum values. */ 125 #define _IO_SKIPWS 01 126 #define _IO_LEFT 02 127 #define _IO_RIGHT 04 128 #define _IO_INTERNAL 010 129 #define _IO_DEC 020 130 #define _IO_OCT 040 131 #define _IO_HEX 0100 132 #define _IO_SHOWBASE 0200 133 #define _IO_SHOWPOINT 0400 134 #define _IO_UPPERCASE 01000 135 #define _IO_SHOWPOS 02000 136 #define _IO_SCIENTIFIC 04000 137 #define _IO_FIXED 010000 138 #define _IO_UNITBUF 020000 139 #define _IO_STDIO 040000 140 #define _IO_DONT_CLOSE 0100000 141 #define _IO_BOOLALPHA 0200000 142 143 struct _IO_jump_t; 144 struct _IO_FILE; 145 146 /* Handle lock. */ 147 #ifdef _IO_MTSAFE_IO 148 # if defined __GLIBC__ && __GLIBC__ >= 2 149 # include <bits/stdio-lock.h> 150 # else 151 /*# include <comthread.h>*/ 152 # endif 153 #else 154 typedef void _IO_lock_t; 155 #endif 156 157 /* A streammarker remembers a position in a buffer. */ 158 159 struct _IO_marker { 160 struct _IO_marker *_next; 161 struct _IO_FILE *_sbuf; 162 /* If _pos >= 0 163 it points to _buf->Gbase()+_pos. FIXME comment */ 164 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */ 165 int _pos; 166 #if 0 167 void set_streampos(streampos sp) { 168 _spos = sp; 169 } void set_offset(int offset) { 170 _pos = offset; 171 _spos = (streampos) (-2); 172 } 173 public: 174 streammarker(streambuf * sb); 175 ~streammarker(); 176 int saving() { 177 return _spos == -2; 178 } 179 int delta(streammarker &); 180 int delta(); 181 #endif 182 }; 183 184 /* This is the structure from the libstdc++ codecvt class. */ 185 enum __codecvt_result { 186 __codecvt_ok, 187 __codecvt_partial, 188 __codecvt_error, 189 __codecvt_noconv 190 }; 191 192 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T 193 /* The order of the elements in the following struct must match the order 194 of the virtual functions in the libstdc++ codecvt class. */ 195 struct _IO_codecvt { 196 void (*__codecvt_destr) (struct _IO_codecvt *); 197 enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *, __mbstate_t *, const wchar_t *, const wchar_t *, const wchar_t **, char *, char *, char **); 198 enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *, __mbstate_t *, char *, char *, char **); 199 enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *, __mbstate_t *, const char *, const char *, const char **, wchar_t *, wchar_t *, wchar_t **); 200 int (*__codecvt_do_encoding) (struct _IO_codecvt *); 201 int (*__codecvt_do_always_noconv) (struct _IO_codecvt *); 202 int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *, const char *, const char *, _IO_size_t); 203 int (*__codecvt_do_max_length) (struct _IO_codecvt *); 204 205 _IO_iconv_t __cd_in; 206 _IO_iconv_t __cd_out; 207 }; 208 209 /* Extra data for wide character streams. */ 210 struct _IO_wide_data { 211 wchar_t *_IO_read_ptr; /* Current read pointer */ 212 wchar_t *_IO_read_end; /* End of get area. */ 213 wchar_t *_IO_read_base; /* Start of putback+get area. */ 214 wchar_t *_IO_write_base; /* Start of put area. */ 215 wchar_t *_IO_write_ptr; /* Current put pointer. */ 216 wchar_t *_IO_write_end; /* End of put area. */ 217 wchar_t *_IO_buf_base; /* Start of reserve area. */ 218 wchar_t *_IO_buf_end; /* End of reserve area. */ 219 /* The following fields are used to support backing up and undo. */ 220 wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */ 221 wchar_t *_IO_backup_base; /* Pointer to first valid character of 222 backup area */ 223 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */ 224 225 __mbstate_t _IO_state; 226 __mbstate_t _IO_last_state; 227 struct _IO_codecvt _codecvt; 228 229 wchar_t _shortbuf[1]; 230 231 const struct _IO_jump_t *_wide_vtable; 232 }; 233 #endif 234 235 struct _IO_FILE { 236 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ 237 #define _IO_file_flags _flags 238 239 /* The following pointers correspond to the C++ streambuf protocol. */ 240 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */ 241 char *_IO_read_ptr; /* Current read pointer */ 242 char *_IO_read_end; /* End of get area. */ 243 char *_IO_read_base; /* Start of putback+get area. */ 244 char *_IO_write_base; /* Start of put area. */ 245 char *_IO_write_ptr; /* Current put pointer. */ 246 char *_IO_write_end; /* End of put area. */ 247 char *_IO_buf_base; /* Start of reserve area. */ 248 char *_IO_buf_end; /* End of reserve area. */ 249 /* The following fields are used to support backing up and undo. */ 250 char *_IO_save_base; /* Pointer to start of non-current get area. */ 251 char *_IO_backup_base; /* Pointer to first valid character of backup area */ 252 char *_IO_save_end; /* Pointer to end of non-current get area. */ 253 254 struct _IO_marker *_markers; 255 256 struct _IO_FILE *_chain; 257 258 int _fileno; 259 #if 0 260 int _blksize; 261 #else 262 int _flags2; 263 #endif 264 _IO_off_t _old_offset; /* This used to be _offset but it's too small. */ 265 266 #define __HAVE_COLUMN /* temporary */ 267 /* 1+column number of pbase(); 0 is unknown. */ 268 unsigned short _cur_column; 269 signed char _vtable_offset; 270 char _shortbuf[1]; 271 272 /* char* _save_gptr; char* _save_egptr; */ 273 274 _IO_lock_t *_lock; 275 #ifdef _IO_USE_OLD_IO_FILE 276 }; 277 278 struct _IO_FILE_complete { 279 struct _IO_FILE _file; 280 #endif 281 #if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001 282 _IO_off64_t _offset; 283 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T 284 /* Wide character stream stuff. */ 285 struct _IO_codecvt *_codecvt; 286 struct _IO_wide_data *_wide_data; 287 struct _IO_FILE *_freeres_list; 288 void *_freeres_buf; 289 size_t _freeres_size; 290 # else 291 void *__pad1; 292 void *__pad2; 293 void *__pad3; 294 void *__pad4; 295 size_t __pad5; 296 # endif 297 int _mode; 298 /* Make sure we don't get into trouble again. */ 299 char _unused2[15 * sizeof(int) - 4 * sizeof(void *) - sizeof(size_t)]; 300 #endif 301 }; 302 303 #ifndef __cplusplus 304 typedef struct _IO_FILE _IO_FILE; 305 #endif 306 307 struct _IO_FILE_plus; 308 309 extern struct _IO_FILE_plus _IO_2_1_stdin_; 310 extern struct _IO_FILE_plus _IO_2_1_stdout_; 311 extern struct _IO_FILE_plus _IO_2_1_stderr_; 312 #ifndef _LIBC 313 #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_)) 314 #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_)) 315 #define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_)) 316 #else 317 extern _IO_FILE *_IO_stdin attribute_hidden; 318 extern _IO_FILE *_IO_stdout attribute_hidden; 319 extern _IO_FILE *_IO_stderr attribute_hidden; 320 #endif 321 322 /* Functions to do I/O and file management for a stream. */ 323 324 /* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF. 325 Return number of bytes read. */ 326 typedef __ssize_t __io_read_fn(void *__cookie, char *__buf, size_t __nbytes); 327 328 /* Write N bytes pointed to by BUF to COOKIE. Write all N bytes 329 unless there is an error. Return number of bytes written. If 330 there is an error, return 0 and do not write anything. If the file 331 has been opened for append (__mode.__append set), then set the file 332 pointer to the end of the file and then do the write; if not, just 333 write at the current file pointer. */ 334 typedef __ssize_t __io_write_fn(void *__cookie, const char *__buf, size_t __n); 335 336 /* Move COOKIE's file position to *POS bytes from the 337 beginning of the file (if W is SEEK_SET), 338 the current position (if W is SEEK_CUR), 339 or the end of the file (if W is SEEK_END). 340 Set *POS to the new file position. 341 Returns zero if successful, nonzero if not. */ 342 typedef int __io_seek_fn(void *__cookie, _IO_off64_t * __pos, int __w); 343 344 /* Close COOKIE. */ 345 typedef int __io_close_fn(void *__cookie); 346 347 #ifdef _GNU_SOURCE 348 /* User-visible names for the above. */ 349 typedef __io_read_fn cookie_read_function_t; 350 typedef __io_write_fn cookie_write_function_t; 351 typedef __io_seek_fn cookie_seek_function_t; 352 typedef __io_close_fn cookie_close_function_t; 353 354 /* The structure with the cookie function pointers. */ 355 typedef struct { 356 __io_read_fn *read; /* Read bytes. */ 357 __io_write_fn *write; /* Write bytes. */ 358 __io_seek_fn *seek; /* Seek/tell file position. */ 359 __io_close_fn *close; /* Close file. */ 360 } _IO_cookie_io_functions_t; 361 typedef _IO_cookie_io_functions_t cookie_io_functions_t; 362 363 struct _IO_cookie_file; 364 365 /* Initialize one of those. */ 366 extern void _IO_cookie_init(struct _IO_cookie_file *__cfile, int __read_write, void *__cookie, _IO_cookie_io_functions_t __fns); 367 #endif 368 369 #ifdef __cplusplus 370 extern "C" { 371 #endif 372 373 extern int __underflow(_IO_FILE *); 374 extern int __uflow(_IO_FILE *); 375 extern int __overflow(_IO_FILE *, int); 376 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T 377 extern _IO_wint_t __wunderflow(_IO_FILE *); 378 extern _IO_wint_t __wuflow(_IO_FILE *); 379 extern _IO_wint_t __woverflow(_IO_FILE *, _IO_wint_t); 380 #endif 381 382 #if __GNUC__ >= 3 383 # define _IO_BE(expr, res) __builtin_expect ((expr), res) 384 #else 385 # define _IO_BE(expr, res) (expr) 386 #endif 387 388 #define _IO_getc_unlocked(_fp) \ 389 (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \ 390 ? __uflow (_fp) : *(unsigned char *) (_fp)->_IO_read_ptr++) 391 #define _IO_peekc_unlocked(_fp) \ 392 (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \ 393 && __underflow (_fp) == EOF ? EOF \ 394 : *(unsigned char *) (_fp)->_IO_read_ptr) 395 #define _IO_putc_unlocked(_ch, _fp) \ 396 (_IO_BE ((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end, 0) \ 397 ? __overflow (_fp, (unsigned char) (_ch)) \ 398 : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) 399 400 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T 401 # define _IO_getwc_unlocked(_fp) \ 402 (_IO_BE ((_fp)->_wide_data == NULL \ 403 || ((_fp)->_wide_data->_IO_read_ptr \ 404 >= (_fp)->_wide_data->_IO_read_end), 0) \ 405 ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++) 406 # define _IO_putwc_unlocked(_wch, _fp) \ 407 (_IO_BE ((_fp)->_wide_data == NULL \ 408 || ((_fp)->_wide_data->_IO_write_ptr \ 409 >= (_fp)->_wide_data->_IO_write_end), 0) \ 410 ? __woverflow (_fp, _wch) \ 411 : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch))) 412 #endif 413 414 #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) 415 #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) 416 417 extern int _IO_getc(_IO_FILE * __fp); 418 extern int _IO_putc(int __c, _IO_FILE * __fp); 419 extern int _IO_feof(_IO_FILE * __fp) __THROW; 420 extern int _IO_ferror(_IO_FILE * __fp) __THROW; 421 422 extern int _IO_peekc_locked(_IO_FILE * __fp); 423 424 /* This one is for Emacs. */ 425 #define _IO_PENDING_OUTPUT_COUNT(_fp) \ 426 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) 427 428 extern void _IO_flockfile(_IO_FILE *) __THROW; 429 extern void _IO_funlockfile(_IO_FILE *) __THROW; 430 extern int _IO_ftrylockfile(_IO_FILE *) __THROW; 431 432 #ifdef _IO_MTSAFE_IO 433 # define _IO_peekc(_fp) _IO_peekc_locked (_fp) 434 # define _IO_flockfile(_fp) \ 435 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp) 436 # define _IO_funlockfile(_fp) \ 437 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp) 438 #else 439 # define _IO_peekc(_fp) _IO_peekc_unlocked (_fp) 440 # define _IO_flockfile(_fp) /**/ 441 # define _IO_funlockfile(_fp) /**/ 442 # define _IO_ftrylockfile(_fp) /**/ 443 # define _IO_cleanup_region_start(_fct, _fp) /**/ 444 # define _IO_cleanup_region_end(_Doit) /**/ 445 #endif /* !_IO_MTSAFE_IO */ 446 extern int _IO_vfscanf(_IO_FILE * __restrict, const char *__restrict, _IO_va_list, int *__restrict); 447 extern int _IO_vfprintf(_IO_FILE * __restrict, const char *__restrict, _IO_va_list); 448 extern _IO_ssize_t _IO_padn(_IO_FILE *, int, _IO_ssize_t); 449 extern _IO_size_t _IO_sgetn(_IO_FILE *, void *, _IO_size_t); 450 451 extern _IO_off64_t _IO_seekoff(_IO_FILE *, _IO_off64_t, int, int); 452 extern _IO_off64_t _IO_seekpos(_IO_FILE *, _IO_off64_t, int); 453 454 extern void _IO_free_backup_area(_IO_FILE *) __THROW; 455 456 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T 457 extern _IO_wint_t _IO_getwc(_IO_FILE * __fp); 458 extern _IO_wint_t _IO_putwc(wchar_t __wc, _IO_FILE * __fp); 459 extern int _IO_fwide(_IO_FILE * __fp, int __mode) __THROW; 460 # if __GNUC__ >= 2 461 /* While compiling glibc we have to handle compatibility with very old 462 versions. */ 463 # if defined _LIBC && defined SHARED 464 # include <shlib-compat.h> 465 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) 466 # define _IO_fwide_maybe_incompatible \ 467 (__builtin_expect (&_IO_stdin_used == NULL, 0)) 468 extern const int _IO_stdin_used; 469 weak_extern(_IO_stdin_used); 470 # endif 471 # endif 472 # ifndef _IO_fwide_maybe_incompatible 473 # define _IO_fwide_maybe_incompatible (0) 474 # endif 475 /* A special optimized version of the function above. It optimizes the 476 case of initializing an unoriented byte stream. */ 477 # define _IO_fwide(__fp, __mode) \ 478 ({ int __result = (__mode); \ 479 if (__result < 0 && ! _IO_fwide_maybe_incompatible) \ 480 { \ 481 if ((__fp)->_mode == 0) \ 482 /* We know that all we have to do is to set the flag. */ \ 483 (__fp)->_mode = -1; \ 484 __result = (__fp)->_mode; \ 485 } \ 486 else if (__builtin_constant_p (__mode) && (__mode) == 0) \ 487 __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode; \ 488 else \ 489 __result = _IO_fwide (__fp, __result); \ 490 __result; }) 491 # endif 492 493 extern int _IO_vfwscanf(_IO_FILE * __restrict, const wchar_t * __restrict, _IO_va_list, int *__restrict); 494 extern int _IO_vfwprintf(_IO_FILE * __restrict, const wchar_t * __restrict, _IO_va_list); 495 extern _IO_ssize_t _IO_wpadn(_IO_FILE *, wint_t, _IO_ssize_t); 496 extern void _IO_free_wbackup_area(_IO_FILE *) __THROW; 497 #endif 498 499 #ifdef __LDBL_COMPAT 500 # include <bits/libio-ldbl.h> 501 #endif 502 503 #ifdef __cplusplus 504 } 505 #endif 506 #endif /* _IO_STDIO_H */