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