OSDN Git Service

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