| 1 | /* Copyright (C) 1991, 92, 93, 94, 95, 97, 1998 Free Software Foundation, Inc.
|
|---|
| 2 | This file is part of the GNU IO Library.
|
|---|
| 3 | Written by Per Bothner <[email protected]>.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU General Public License as
|
|---|
| 7 | published by the Free Software Foundation; either version 2, or (at
|
|---|
| 8 | your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful, but
|
|---|
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this library; see the file COPYING. If not, write to
|
|---|
| 17 | the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
|---|
| 18 | MA 02111-1307, USA.
|
|---|
| 19 |
|
|---|
| 20 | As a special exception, if you link this library with files
|
|---|
| 21 | compiled with a GNU compiler to produce an executable, this does
|
|---|
| 22 | not cause the resulting executable to be covered by the GNU General
|
|---|
| 23 | Public License. This exception does not however invalidate any
|
|---|
| 24 | other reasons why the executable file might be covered by the GNU
|
|---|
| 25 | General Public License. */
|
|---|
| 26 |
|
|---|
| 27 | #ifndef _IO_STDIO_H
|
|---|
| 28 | #define _IO_STDIO_H
|
|---|
| 29 |
|
|---|
| 30 | #include <_G_confi.h>
|
|---|
| 31 | #define _IO_pos_t _G_fpos_t /* obsolete */
|
|---|
| 32 | #define _IO_fpos_t _G_fpos_t
|
|---|
| 33 | #define _IO_size_t _G_size_t
|
|---|
| 34 | #define _IO_ssize_t _G_ssize_t
|
|---|
| 35 | #define _IO_off_t _G_off_t
|
|---|
| 36 | #define _IO_pid_t _G_pid_t
|
|---|
| 37 | #define _IO_uid_t _G_uid_t
|
|---|
| 38 | #define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
|
|---|
| 39 | #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
|
|---|
| 40 | #define _IO_BUFSIZ _G_BUFSIZ
|
|---|
| 41 | #define _IO_va_list _G_va_list
|
|---|
| 42 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
|---|
| 43 | #define _IO_fpos64_t _G_fpos64_t
|
|---|
| 44 | #define _IO_off64_t _G_off64_t
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| 47 | #ifdef _G_NEED_STDARG_H
|
|---|
| 48 | /* This define avoids name pollution if we're using GNU stdarg.h */
|
|---|
| 49 | # define __need___va_list
|
|---|
| 50 | # include <stdarg.h>
|
|---|
| 51 | # ifdef __GNUC_VA_LIST
|
|---|
| 52 | # undef _IO_va_list
|
|---|
| 53 | # define _IO_va_list __gnuc_va_list
|
|---|
| 54 | # endif /* __GNUC_VA_LIST */
|
|---|
| 55 | #endif
|
|---|
| 56 |
|
|---|
| 57 | #ifndef __P
|
|---|
| 58 | # if _G_HAVE_SYS_CDEFS
|
|---|
| 59 | # include <sys/cdefs.h>
|
|---|
| 60 | # else
|
|---|
| 61 | # ifdef __STDC__
|
|---|
| 62 | # define __P(protos) protos
|
|---|
| 63 | # else
|
|---|
| 64 | # define __P(protos) ()
|
|---|
| 65 | # endif
|
|---|
| 66 | # endif
|
|---|
| 67 | #endif /*!__P*/
|
|---|
| 68 |
|
|---|
| 69 | /* For backward compatibility */
|
|---|
| 70 | #ifndef _PARAMS
|
|---|
| 71 | # define _PARAMS(protos) __P(protos)
|
|---|
| 72 | #endif /*!_PARAMS*/
|
|---|
| 73 |
|
|---|
| 74 | #ifndef __STDC__
|
|---|
| 75 | # define const
|
|---|
| 76 | #endif
|
|---|
| 77 | #define _IO_UNIFIED_JUMPTABLES 1
|
|---|
| 78 | #if !_G_HAVE_PRINTF_FP
|
|---|
| 79 | # define _IO_USE_DTOA 1
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | #ifndef EOF
|
|---|
| 83 | # define EOF (-1)
|
|---|
| 84 | #endif
|
|---|
| 85 | #ifndef NULL
|
|---|
| 86 | # if defined __GNUG__ && \
|
|---|
| 87 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
|
|---|
| 88 | # define NULL (__null)
|
|---|
| 89 | # else
|
|---|
| 90 | # if !defined(__cplusplus)
|
|---|
| 91 | # define NULL ((void*)0)
|
|---|
| 92 | # else
|
|---|
| 93 | # define NULL (0)
|
|---|
| 94 | # endif
|
|---|
| 95 | # endif
|
|---|
| 96 | #endif
|
|---|
| 97 |
|
|---|
| 98 | #define _IOS_INPUT 1
|
|---|
| 99 | #define _IOS_OUTPUT 2
|
|---|
| 100 | #define _IOS_ATEND 4
|
|---|
| 101 | #define _IOS_APPEND 8
|
|---|
| 102 | #define _IOS_TRUNC 16
|
|---|
| 103 | #define _IOS_NOCREATE 32
|
|---|
| 104 | #define _IOS_NOREPLACE 64
|
|---|
| 105 | #define _IOS_BIN 128
|
|---|
| 106 |
|
|---|
| 107 | /* Magic numbers and bits for the _flags field.
|
|---|
| 108 | The magic numbers use the high-order bits of _flags;
|
|---|
| 109 | the remaining bits are available for variable flags.
|
|---|
| 110 | Note: The magic numbers must all be negative if stdio
|
|---|
| 111 | emulation is desired. */
|
|---|
| 112 |
|
|---|
| 113 | #define _IO_MAGIC 0xFBAD0000 /* Magic number */
|
|---|
| 114 | #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
|
|---|
| 115 | #define _IO_MAGIC_MASK 0xFFFF0000
|
|---|
| 116 | #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
|
|---|
| 117 | #define _IO_UNBUFFERED 2
|
|---|
| 118 | #define _IO_NO_READS 4 /* Reading not allowed */
|
|---|
| 119 | #define _IO_NO_WRITES 8 /* Writing not allowd */
|
|---|
| 120 | #define _IO_EOF_SEEN 0x10
|
|---|
| 121 | #define _IO_ERR_SEEN 0x20
|
|---|
| 122 | #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
|
|---|
| 123 | #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
|
|---|
| 124 | #define _IO_IN_BACKUP 0x100
|
|---|
| 125 | #define _IO_LINE_BUF 0x200
|
|---|
| 126 | #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
|
|---|
| 127 | #define _IO_CURRENTLY_PUTTING 0x800
|
|---|
| 128 | #define _IO_IS_APPENDING 0x1000
|
|---|
| 129 | #define _IO_IS_FILEBUF 0x2000
|
|---|
| 130 | #define _IO_BAD_SEEN 0x4000
|
|---|
| 131 |
|
|---|
| 132 | /* These are "formatting flags" matching the iostream fmtflags enum values. */
|
|---|
| 133 | #define _IO_SKIPWS 01
|
|---|
| 134 | #define _IO_LEFT 02
|
|---|
| 135 | #define _IO_RIGHT 04
|
|---|
| 136 | #define _IO_INTERNAL 010
|
|---|
| 137 | #define _IO_DEC 020
|
|---|
| 138 | #define _IO_OCT 040
|
|---|
| 139 | #define _IO_HEX 0100
|
|---|
| 140 | #define _IO_SHOWBASE 0200
|
|---|
| 141 | #define _IO_SHOWPOINT 0400
|
|---|
| 142 | #define _IO_UPPERCASE 01000
|
|---|
| 143 | #define _IO_SHOWPOS 02000
|
|---|
| 144 | #define _IO_SCIENTIFIC 04000
|
|---|
| 145 | #define _IO_FIXED 010000
|
|---|
| 146 | #define _IO_UNITBUF 020000
|
|---|
| 147 | #define _IO_STDIO 040000
|
|---|
| 148 | #define _IO_DONT_CLOSE 0100000
|
|---|
| 149 | #define _IO_BOOLALPHA 0200000
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | struct _IO_jump_t; struct _IO_FILE;
|
|---|
| 153 |
|
|---|
| 154 | /* Handle lock. */
|
|---|
| 155 | #ifdef _IO_MTSAFE_IO
|
|---|
| 156 | # if defined __GLIBC__ && __GLIBC__ >= 2
|
|---|
| 157 | # if __GLIBC_MINOR__ > 0
|
|---|
| 158 | # include <bits/stdio-lock.h>
|
|---|
| 159 | # else
|
|---|
| 160 | # include <stdio-lock.h>
|
|---|
| 161 | # endif
|
|---|
| 162 | # define _IO_LOCK_T _IO_lock_t *
|
|---|
| 163 | # else
|
|---|
| 164 | /*# include <comthread.h>*/
|
|---|
| 165 | # endif
|
|---|
| 166 | #else
|
|---|
| 167 | # if defined(__GLIBC__) && __GLIBC__ >= 2
|
|---|
| 168 | typedef void _IO_lock_t;
|
|---|
| 169 | # define _IO_LOCK_T void *
|
|---|
| 170 | # else
|
|---|
| 171 | # ifdef __linux__
|
|---|
| 172 | struct _IO_lock_t { void *ptr; short int field1; short int field2; };
|
|---|
| 173 | # define _IO_LOCK_T struct _IO_lock_t
|
|---|
| 174 | # else
|
|---|
| 175 | typedef void _IO_lock_t;
|
|---|
| 176 | # endif
|
|---|
| 177 | # endif
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | /* A streammarker remembers a position in a buffer. */
|
|---|
| 182 |
|
|---|
| 183 | struct _IO_marker {
|
|---|
| 184 | struct _IO_marker *_next;
|
|---|
| 185 | struct _IO_FILE *_sbuf;
|
|---|
| 186 | /* If _pos >= 0
|
|---|
| 187 | it points to _buf->Gbase()+_pos. FIXME comment */
|
|---|
| 188 | /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
|
|---|
| 189 | int _pos;
|
|---|
| 190 | #if 0
|
|---|
| 191 | void set_streampos(streampos sp) { _spos = sp; }
|
|---|
| 192 | void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
|
|---|
| 193 | public:
|
|---|
| 194 | streammarker(streambuf *sb);
|
|---|
| 195 | ~streammarker();
|
|---|
| 196 | int saving() { return _spos == -2; }
|
|---|
| 197 | int delta(streammarker&);
|
|---|
| 198 | int delta();
|
|---|
| 199 | #endif
|
|---|
| 200 | };
|
|---|
| 201 |
|
|---|
| 202 | struct _IO_FILE {
|
|---|
| 203 | int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
|
|---|
| 204 | #define _IO_file_flags _flags
|
|---|
| 205 |
|
|---|
| 206 | /* The following pointers correspond to the C++ streambuf protocol. */
|
|---|
| 207 | /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
|
|---|
| 208 | char* _IO_read_ptr; /* Current read pointer */
|
|---|
| 209 | char* _IO_read_end; /* End of get area. */
|
|---|
| 210 | char* _IO_read_base; /* Start of putback+get area. */
|
|---|
| 211 | char* _IO_write_base; /* Start of put area. */
|
|---|
| 212 | char* _IO_write_ptr; /* Current put pointer. */
|
|---|
| 213 | char* _IO_write_end; /* End of put area. */
|
|---|
| 214 | char* _IO_buf_base; /* Start of reserve area. */
|
|---|
| 215 | char* _IO_buf_end; /* End of reserve area. */
|
|---|
| 216 | /* The following fields are used to support backing up and undo. */
|
|---|
| 217 | char *_IO_save_base; /* Pointer to start of non-current get area. */
|
|---|
| 218 | char *_IO_backup_base; /* Pointer to first valid character of backup area */
|
|---|
| 219 | char *_IO_save_end; /* Pointer to end of non-current get area. */
|
|---|
| 220 |
|
|---|
| 221 | struct _IO_marker *_markers;
|
|---|
| 222 |
|
|---|
| 223 | struct _IO_FILE *_chain;
|
|---|
| 224 |
|
|---|
| 225 | int _fileno;
|
|---|
| 226 | int _blksize;
|
|---|
| 227 | #ifdef _G_IO_IO_FILE_VERSION
|
|---|
| 228 | _IO_off_t _old_offset;
|
|---|
| 229 | #else
|
|---|
| 230 | _IO_off_t _offset;
|
|---|
| 231 | #endif
|
|---|
| 232 |
|
|---|
| 233 | #define __HAVE_COLUMN /* temporary */
|
|---|
| 234 | /* 1+column number of pbase(); 0 is unknown. */
|
|---|
| 235 | unsigned short _cur_column;
|
|---|
| 236 | char _unused;
|
|---|
| 237 | char _shortbuf[1];
|
|---|
| 238 |
|
|---|
| 239 | /* char* _save_gptr; char* _save_egptr; */
|
|---|
| 240 |
|
|---|
| 241 | #ifdef _IO_LOCK_T
|
|---|
| 242 | _IO_LOCK_T _lock;
|
|---|
| 243 | #endif
|
|---|
| 244 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
|---|
| 245 | _IO_off64_t _offset;
|
|---|
| 246 | int _unused2[16]; /* Make sure we don't get into trouble again. */
|
|---|
| 247 | #endif
|
|---|
| 248 | };
|
|---|
| 249 |
|
|---|
| 250 | #ifndef __cplusplus
|
|---|
| 251 | typedef struct _IO_FILE _IO_FILE;
|
|---|
| 252 | #endif
|
|---|
| 253 |
|
|---|
| 254 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
|---|
| 255 | #define _IO_stdin_ _IO_2_1_stdin_
|
|---|
| 256 | #define _IO_stdout_ _IO_2_1_stdout_
|
|---|
| 257 | #define _IO_stderr_ _IO_2_1_stderr_
|
|---|
| 258 | #endif
|
|---|
| 259 |
|
|---|
| 260 | struct _IO_FILE_plus;
|
|---|
| 261 | extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
|
|---|
| 262 | #define _IO_stdin ((_IO_FILE*)(&_IO_stdin_))
|
|---|
| 263 | #define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
|
|---|
| 264 | #define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 | /* Define the user-visible type, with user-friendly member names. */
|
|---|
| 268 | typedef struct
|
|---|
| 269 | {
|
|---|
| 270 | _IO_ssize_t (*read) __P ((struct _IO_FILE *, void *, _IO_ssize_t));
|
|---|
| 271 | _IO_ssize_t (*write) __P ((struct _IO_FILE *, const void *, _IO_ssize_t));
|
|---|
| 272 | _IO_fpos_t (*seek) __P ((struct _IO_FILE *, _IO_off_t, int));
|
|---|
| 273 | int (*close) __P ((struct _IO_FILE *));
|
|---|
| 274 | } _IO_cookie_io_functions_t;
|
|---|
| 275 |
|
|---|
| 276 | /* Special file type for fopencookie function. */
|
|---|
| 277 | struct _IO_cookie_file
|
|---|
| 278 | {
|
|---|
| 279 | struct _IO_FILE file;
|
|---|
| 280 | const void *vtable;
|
|---|
| 281 | void *cookie;
|
|---|
| 282 | _IO_cookie_io_functions_t io_functions;
|
|---|
| 283 | };
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 | #ifdef __cplusplus
|
|---|
| 287 | extern "C" {
|
|---|
| 288 | #endif
|
|---|
| 289 |
|
|---|
| 290 | extern int __underflow __P ((_IO_FILE *));
|
|---|
| 291 | extern int __uflow __P ((_IO_FILE *));
|
|---|
| 292 | extern int __overflow __P ((_IO_FILE *, int));
|
|---|
| 293 |
|
|---|
| 294 | #define _IO_getc_unlocked(_fp) \
|
|---|
| 295 | ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
|
|---|
| 296 | : *(unsigned char *) (_fp)->_IO_read_ptr++)
|
|---|
| 297 | #define _IO_peekc_unlocked(_fp) \
|
|---|
| 298 | ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
|
|---|
| 299 | && __underflow (_fp) == EOF ? EOF \
|
|---|
| 300 | : *(unsigned char *) (_fp)->_IO_read_ptr)
|
|---|
| 301 |
|
|---|
| 302 | #define _IO_putc_unlocked(_ch, _fp) \
|
|---|
| 303 | (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
|
|---|
| 304 | ? __overflow (_fp, (unsigned char) (_ch)) \
|
|---|
| 305 | : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
|
|---|
| 306 |
|
|---|
| 307 | #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
|
|---|
| 308 | #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
|
|---|
| 309 |
|
|---|
| 310 | extern int _IO_getc __P ((_IO_FILE *__fp));
|
|---|
| 311 | extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
|
|---|
| 312 | extern int _IO_feof __P ((_IO_FILE *__fp));
|
|---|
| 313 | extern int _IO_ferror __P ((_IO_FILE *__fp));
|
|---|
| 314 |
|
|---|
| 315 | extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
|
|---|
| 316 |
|
|---|
| 317 | /* This one is for Emacs. */
|
|---|
| 318 | #define _IO_PENDING_OUTPUT_COUNT(_fp) \
|
|---|
| 319 | ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
|
|---|
| 320 |
|
|---|
| 321 | extern void _IO_flockfile __P ((_IO_FILE *));
|
|---|
| 322 | extern void _IO_funlockfile __P ((_IO_FILE *));
|
|---|
| 323 | extern int _IO_ftrylockfile __P ((_IO_FILE *));
|
|---|
| 324 |
|
|---|
| 325 | #ifdef _IO_MTSAFE_IO
|
|---|
| 326 | # define _IO_peekc(_fp) _IO_peekc_locked (_fp)
|
|---|
| 327 | #else
|
|---|
| 328 | # define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
|
|---|
| 329 | # define _IO_flockfile(_fp) /**/
|
|---|
| 330 | # define _IO_funlockfile(_fp) /**/
|
|---|
| 331 | # define _IO_ftrylockfile(_fp) /**/
|
|---|
| 332 | # define _IO_cleanup_region_start(_fct, _fp) /**/
|
|---|
| 333 | # define _IO_cleanup_region_end(_Doit) /**/
|
|---|
| 334 | #endif /* !_IO_MTSAFE_IO */
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 | extern int _IO_vfscanf __P ((_IO_FILE *, const char *, _IO_va_list, int *));
|
|---|
| 338 | extern int _IO_vfprintf __P ((_IO_FILE *, const char *, _IO_va_list));
|
|---|
| 339 | extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t));
|
|---|
| 340 | extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t));
|
|---|
| 341 |
|
|---|
| 342 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
|
|---|
| 343 | extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
|
|---|
| 344 | extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int));
|
|---|
| 345 | #else
|
|---|
| 346 | extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
|
|---|
| 347 | extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int));
|
|---|
| 348 | #endif
|
|---|
| 349 |
|
|---|
| 350 | extern void _IO_free_backup_area __P ((_IO_FILE *));
|
|---|
| 351 |
|
|---|
| 352 | #ifdef __cplusplus
|
|---|
| 353 | }
|
|---|
| 354 | #endif
|
|---|
| 355 |
|
|---|
| 356 | #endif /* _IO_STDIO_H */
|
|---|