]>
Commit | Line | Data |
---|---|---|
e6cc3b80 | 1 | /* Copyright (C) 1991, 92, 93, 94, 95, 97, 98 Free Software Foundation, Inc. |
e693cc28 UD |
2 | This file is part of the GNU IO Library. |
3 | Written by Per Bothner <bothner@cygnus.com>. | |
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. */ | |
6599da04 JM |
26 | |
27 | #ifndef _IO_STDIO_H | |
28 | #define _IO_STDIO_H | |
29 | ||
30 | #include <_G_config.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 | |
2b0aa3c5 L |
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 | |
6599da04 JM |
46 | |
47 | #ifdef _G_NEED_STDARG_H | |
48 | /* This define avoids name pollution if we're using GNU stdarg.h */ | |
e693cc28 UD |
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 */ | |
6599da04 JM |
55 | #endif |
56 | ||
57 | #ifndef __P | |
e693cc28 UD |
58 | # if _G_HAVE_SYS_CDEFS |
59 | # include <sys/cdefs.h> | |
60 | # else | |
61 | # ifdef __STDC__ | |
6564e475 | 62 | # define __P(p) p |
e693cc28 | 63 | # else |
6564e475 | 64 | # define __P(p) () |
e693cc28 UD |
65 | # endif |
66 | # endif | |
6599da04 JM |
67 | #endif /*!__P*/ |
68 | ||
9ca05bb1 UD |
69 | #ifndef __PMT |
70 | # ifdef __STDC__ | |
71 | # define __PMT(p) p | |
72 | # else | |
73 | # define __PMT(p) () | |
74 | # endif | |
75 | #endif /*!__P*/ | |
76 | ||
6599da04 JM |
77 | /* For backward compatibility */ |
78 | #ifndef _PARAMS | |
e693cc28 | 79 | # define _PARAMS(protos) __P(protos) |
6599da04 JM |
80 | #endif /*!_PARAMS*/ |
81 | ||
82 | #ifndef __STDC__ | |
e693cc28 | 83 | # define const |
6599da04 JM |
84 | #endif |
85 | #define _IO_UNIFIED_JUMPTABLES 1 | |
c44e099f | 86 | #if !_G_HAVE_PRINTF_FP |
6c1d5706 UD |
87 | # define _IO_USE_DTOA 1 |
88 | #endif | |
6599da04 | 89 | |
6599da04 | 90 | #ifndef EOF |
e693cc28 | 91 | # define EOF (-1) |
6599da04 JM |
92 | #endif |
93 | #ifndef NULL | |
e693cc28 UD |
94 | # if defined __GNUG__ && \ |
95 | (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) | |
96 | # define NULL (__null) | |
97 | # else | |
98 | # if !defined(__cplusplus) | |
99 | # define NULL ((void*)0) | |
100 | # else | |
101 | # define NULL (0) | |
102 | # endif | |
103 | # endif | |
6599da04 JM |
104 | #endif |
105 | ||
106 | #define _IOS_INPUT 1 | |
107 | #define _IOS_OUTPUT 2 | |
108 | #define _IOS_ATEND 4 | |
109 | #define _IOS_APPEND 8 | |
110 | #define _IOS_TRUNC 16 | |
111 | #define _IOS_NOCREATE 32 | |
112 | #define _IOS_NOREPLACE 64 | |
113 | #define _IOS_BIN 128 | |
114 | ||
115 | /* Magic numbers and bits for the _flags field. | |
116 | The magic numbers use the high-order bits of _flags; | |
e693cc28 | 117 | the remaining bits are available for variable flags. |
6599da04 JM |
118 | Note: The magic numbers must all be negative if stdio |
119 | emulation is desired. */ | |
120 | ||
121 | #define _IO_MAGIC 0xFBAD0000 /* Magic number */ | |
122 | #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */ | |
123 | #define _IO_MAGIC_MASK 0xFFFF0000 | |
124 | #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */ | |
125 | #define _IO_UNBUFFERED 2 | |
126 | #define _IO_NO_READS 4 /* Reading not allowed */ | |
127 | #define _IO_NO_WRITES 8 /* Writing not allowd */ | |
128 | #define _IO_EOF_SEEN 0x10 | |
129 | #define _IO_ERR_SEEN 0x20 | |
130 | #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */ | |
131 | #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/ | |
132 | #define _IO_IN_BACKUP 0x100 | |
133 | #define _IO_LINE_BUF 0x200 | |
134 | #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */ | |
135 | #define _IO_CURRENTLY_PUTTING 0x800 | |
136 | #define _IO_IS_APPENDING 0x1000 | |
137 | #define _IO_IS_FILEBUF 0x2000 | |
e693cc28 | 138 | #define _IO_BAD_SEEN 0x4000 |
6599da04 JM |
139 | |
140 | /* These are "formatting flags" matching the iostream fmtflags enum values. */ | |
141 | #define _IO_SKIPWS 01 | |
142 | #define _IO_LEFT 02 | |
143 | #define _IO_RIGHT 04 | |
144 | #define _IO_INTERNAL 010 | |
145 | #define _IO_DEC 020 | |
146 | #define _IO_OCT 040 | |
147 | #define _IO_HEX 0100 | |
148 | #define _IO_SHOWBASE 0200 | |
149 | #define _IO_SHOWPOINT 0400 | |
150 | #define _IO_UPPERCASE 01000 | |
151 | #define _IO_SHOWPOS 02000 | |
152 | #define _IO_SCIENTIFIC 04000 | |
153 | #define _IO_FIXED 010000 | |
154 | #define _IO_UNITBUF 020000 | |
155 | #define _IO_STDIO 040000 | |
156 | #define _IO_DONT_CLOSE 0100000 | |
e693cc28 | 157 | #define _IO_BOOLALPHA 0200000 |
6599da04 | 158 | |
6599da04 JM |
159 | |
160 | struct _IO_jump_t; struct _IO_FILE; | |
161 | ||
dbfcb4be BK |
162 | /* Handle lock. */ |
163 | #ifdef _IO_MTSAFE_IO | |
d604f4c6 | 164 | # if defined __GLIBC__ && __GLIBC__ >= 2 |
20a2fbe2 RH |
165 | # if __GLIBC_MINOR__ > 0 |
166 | # include <bits/stdio-lock.h> | |
167 | # else | |
168 | # include <stdio-lock.h> | |
169 | # endif | |
d604f4c6 UD |
170 | # define _IO_LOCK_T _IO_lock_t * |
171 | # else | |
172 | /*# include <comthread.h>*/ | |
173 | # endif | |
dbfcb4be | 174 | #else |
20a2fbe2 RH |
175 | # if defined(__GLIBC__) && __GLIBC__ >= 2 |
176 | typedef void _IO_lock_t; | |
1181d2d5 L |
177 | # define _IO_LOCK_T void * |
178 | # else | |
179 | # ifdef __linux__ | |
20a2fbe2 | 180 | struct _IO_lock_t { void *ptr; short int field1; short int field2; }; |
1181d2d5 | 181 | # define _IO_LOCK_T struct _IO_lock_t |
20a2fbe2 RH |
182 | # else |
183 | typedef void _IO_lock_t; | |
1181d2d5 | 184 | # endif |
d604f4c6 | 185 | # endif |
dbfcb4be BK |
186 | #endif |
187 | ||
188 | ||
e693cc28 UD |
189 | /* A streammarker remembers a position in a buffer. */ |
190 | ||
6599da04 JM |
191 | struct _IO_marker { |
192 | struct _IO_marker *_next; | |
193 | struct _IO_FILE *_sbuf; | |
194 | /* If _pos >= 0 | |
195 | it points to _buf->Gbase()+_pos. FIXME comment */ | |
196 | /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */ | |
197 | int _pos; | |
198 | #if 0 | |
199 | void set_streampos(streampos sp) { _spos = sp; } | |
200 | void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); } | |
201 | public: | |
202 | streammarker(streambuf *sb); | |
203 | ~streammarker(); | |
204 | int saving() { return _spos == -2; } | |
205 | int delta(streammarker&); | |
206 | int delta(); | |
207 | #endif | |
208 | }; | |
209 | ||
210 | struct _IO_FILE { | |
e693cc28 | 211 | int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ |
6599da04 JM |
212 | #define _IO_file_flags _flags |
213 | ||
214 | /* The following pointers correspond to the C++ streambuf protocol. */ | |
215 | /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */ | |
216 | char* _IO_read_ptr; /* Current read pointer */ | |
217 | char* _IO_read_end; /* End of get area. */ | |
218 | char* _IO_read_base; /* Start of putback+get area. */ | |
219 | char* _IO_write_base; /* Start of put area. */ | |
220 | char* _IO_write_ptr; /* Current put pointer. */ | |
221 | char* _IO_write_end; /* End of put area. */ | |
222 | char* _IO_buf_base; /* Start of reserve area. */ | |
223 | char* _IO_buf_end; /* End of reserve area. */ | |
224 | /* The following fields are used to support backing up and undo. */ | |
225 | char *_IO_save_base; /* Pointer to start of non-current get area. */ | |
226 | char *_IO_backup_base; /* Pointer to first valid character of backup area */ | |
227 | char *_IO_save_end; /* Pointer to end of non-current get area. */ | |
228 | ||
229 | struct _IO_marker *_markers; | |
dbfcb4be | 230 | |
6599da04 | 231 | struct _IO_FILE *_chain; |
dbfcb4be | 232 | |
6599da04 JM |
233 | int _fileno; |
234 | int _blksize; | |
2b0aa3c5 L |
235 | #ifdef _G_IO_IO_FILE_VERSION |
236 | _IO_off_t _old_offset; | |
237 | #else | |
6599da04 | 238 | _IO_off_t _offset; |
2b0aa3c5 | 239 | #endif |
dbfcb4be | 240 | |
6599da04 JM |
241 | #define __HAVE_COLUMN /* temporary */ |
242 | /* 1+column number of pbase(); 0 is unknown. */ | |
243 | unsigned short _cur_column; | |
244 | char _unused; | |
245 | char _shortbuf[1]; | |
dbfcb4be | 246 | |
6599da04 | 247 | /* char* _save_gptr; char* _save_egptr; */ |
dbfcb4be | 248 | |
e741306e | 249 | #ifdef _IO_LOCK_T |
d604f4c6 | 250 | _IO_LOCK_T _lock; |
e741306e | 251 | #endif |
2b0aa3c5 L |
252 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 |
253 | _IO_off64_t _offset; | |
254 | int _unused2[16]; /* Make sure we don't get into trouble again. */ | |
255 | #endif | |
6599da04 JM |
256 | }; |
257 | ||
258 | #ifndef __cplusplus | |
259 | typedef struct _IO_FILE _IO_FILE; | |
260 | #endif | |
261 | ||
2b0aa3c5 L |
262 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 |
263 | #define _IO_stdin_ _IO_2_1_stdin_ | |
264 | #define _IO_stdout_ _IO_2_1_stdout_ | |
265 | #define _IO_stderr_ _IO_2_1_stderr_ | |
266 | #endif | |
267 | ||
6599da04 JM |
268 | struct _IO_FILE_plus; |
269 | extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_; | |
270 | #define _IO_stdin ((_IO_FILE*)(&_IO_stdin_)) | |
271 | #define _IO_stdout ((_IO_FILE*)(&_IO_stdout_)) | |
272 | #define _IO_stderr ((_IO_FILE*)(&_IO_stderr_)) | |
273 | ||
dbfcb4be BK |
274 | |
275 | /* Define the user-visible type, with user-friendly member names. */ | |
276 | typedef struct | |
277 | { | |
e6cc3b80 UD |
278 | _IO_ssize_t (*read) __PMT ((struct _IO_FILE *, void *, _IO_ssize_t)); |
279 | _IO_ssize_t (*write) __PMT ((struct _IO_FILE *, const void *, _IO_ssize_t)); | |
280 | _IO_fpos_t (*seek) __PMT ((struct _IO_FILE *, _IO_off_t, int)); | |
281 | int (*close) __PMT ((struct _IO_FILE *)); | |
dbfcb4be BK |
282 | } _IO_cookie_io_functions_t; |
283 | ||
284 | /* Special file type for fopencookie function. */ | |
285 | struct _IO_cookie_file | |
286 | { | |
287 | struct _IO_FILE file; | |
288 | const void *vtable; | |
289 | void *cookie; | |
290 | _IO_cookie_io_functions_t io_functions; | |
291 | }; | |
292 | ||
293 | ||
6599da04 JM |
294 | #ifdef __cplusplus |
295 | extern "C" { | |
296 | #endif | |
297 | ||
e693cc28 UD |
298 | extern int __underflow __P ((_IO_FILE *)); |
299 | extern int __uflow __P ((_IO_FILE *)); | |
300 | extern int __overflow __P ((_IO_FILE *, int)); | |
6599da04 | 301 | |
dbfcb4be | 302 | #define _IO_getc_unlocked(_fp) \ |
e693cc28 UD |
303 | ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \ |
304 | : *(unsigned char *) (_fp)->_IO_read_ptr++) | |
dbfcb4be | 305 | #define _IO_peekc_unlocked(_fp) \ |
6599da04 | 306 | ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \ |
e693cc28 UD |
307 | && __underflow (_fp) == EOF ? EOF \ |
308 | : *(unsigned char *) (_fp)->_IO_read_ptr) | |
6599da04 | 309 | |
dbfcb4be | 310 | #define _IO_putc_unlocked(_ch, _fp) \ |
6599da04 | 311 | (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \ |
e693cc28 UD |
312 | ? __overflow (_fp, (unsigned char) (_ch)) \ |
313 | : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) | |
6599da04 | 314 | |
2ce72aa0 | 315 | #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) |
dbfcb4be BK |
316 | #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) |
317 | ||
318 | extern int _IO_getc __P ((_IO_FILE *__fp)); | |
319 | extern int _IO_putc __P ((int __c, _IO_FILE *__fp)); | |
320 | extern int _IO_feof __P ((_IO_FILE *__fp)); | |
321 | extern int _IO_ferror __P ((_IO_FILE *__fp)); | |
322 | ||
323 | extern int _IO_peekc_locked __P ((_IO_FILE *__fp)); | |
6599da04 JM |
324 | |
325 | /* This one is for Emacs. */ | |
326 | #define _IO_PENDING_OUTPUT_COUNT(_fp) \ | |
327 | ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) | |
328 | ||
dbfcb4be BK |
329 | extern void _IO_flockfile __P ((_IO_FILE *)); |
330 | extern void _IO_funlockfile __P ((_IO_FILE *)); | |
331 | extern int _IO_ftrylockfile __P ((_IO_FILE *)); | |
332 | ||
d604f4c6 UD |
333 | #ifdef _IO_MTSAFE_IO |
334 | # define _IO_peekc(_fp) _IO_peekc_locked (_fp) | |
335 | #else | |
336 | # define _IO_peekc(_fp) _IO_peekc_unlocked (_fp) | |
dbfcb4be BK |
337 | # define _IO_flockfile(_fp) /**/ |
338 | # define _IO_funlockfile(_fp) /**/ | |
339 | # define _IO_ftrylockfile(_fp) /**/ | |
340 | # define _IO_cleanup_region_start(_fct, _fp) /**/ | |
341 | # define _IO_cleanup_region_end(_Doit) /**/ | |
342 | #endif /* !_IO_MTSAFE_IO */ | |
343 | ||
dbfcb4be | 344 | |
e693cc28 UD |
345 | extern int _IO_vfscanf __P ((_IO_FILE *, const char *, _IO_va_list, int *)); |
346 | extern int _IO_vfprintf __P ((_IO_FILE *, const char *, _IO_va_list)); | |
347 | extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t)); | |
348 | extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t)); | |
6599da04 | 349 | |
2b0aa3c5 | 350 | #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 |
e6cc3b80 | 351 | extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); |
2b0aa3c5 L |
352 | extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int)); |
353 | #else | |
e693cc28 UD |
354 | extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); |
355 | extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int)); | |
2b0aa3c5 | 356 | #endif |
6599da04 | 357 | |
e693cc28 | 358 | extern void _IO_free_backup_area __P ((_IO_FILE *)); |
6599da04 JM |
359 | |
360 | #ifdef __cplusplus | |
361 | } | |
362 | #endif | |
363 | ||
364 | #endif /* _IO_STDIO_H */ |