OSDN Git Service

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