1129198Scognet/* Copyright (C) 1991, 92, 93, 94, 95, 97, 98 Free Software Foundation, Inc. 2129198Scognet This file is part of the GNU IO Library. 3129198Scognet Written by Per Bothner <bothner@cygnus.com>. 4129198Scognet 5129198Scognet This library is free software; you can redistribute it and/or 6129198Scognet modify it under the terms of the GNU General Public License as 7129198Scognet published by the Free Software Foundation; either version 2, or (at 8129198Scognet your option) any later version. 9129198Scognet 10129198Scognet This library is distributed in the hope that it will be useful, but 11129198Scognet WITHOUT ANY WARRANTY; without even the implied warranty of 12129198Scognet MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13129198Scognet General Public License for more details. 14129198Scognet 15129198Scognet You should have received a copy of the GNU General Public License 16129198Scognet along with this library; see the file COPYING. If not, write to 17129198Scognet the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 18129198Scognet MA 02111-1307, USA. 19129198Scognet 20129198Scognet As a special exception, if you link this library with files 21129198Scognet compiled with a GNU compiler to produce an executable, this does 22129198Scognet not cause the resulting executable to be covered by the GNU General 23129198Scognet Public License. This exception does not however invalidate any 24129198Scognet other reasons why the executable file might be covered by the GNU 25129198Scognet General Public License. */ 26129198Scognet 27129198Scognet#ifndef _IO_STDIO_H 28129198Scognet#define _IO_STDIO_H 29129198Scognet 30129198Scognet#include <_G_config.h> 31129198Scognet#define _IO_pos_t _G_fpos_t /* obsolete */ 32129198Scognet#define _IO_fpos_t _G_fpos_t 33129198Scognet#define _IO_size_t _G_size_t 34129198Scognet#define _IO_ssize_t _G_ssize_t 35239268Sgonzo#define _IO_off_t _G_off_t 36129198Scognet#define _IO_pid_t _G_pid_t 37129198Scognet#define _IO_uid_t _G_uid_t 38129198Scognet#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT 39129198Scognet#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE 40129198Scognet#define _IO_BUFSIZ _G_BUFSIZ 41181875Sjhb#define _IO_va_list _G_va_list 42181875Sjhb#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 43254461Sandrew#define _IO_fpos64_t _G_fpos64_t 44239268Sgonzo#define _IO_off64_t _G_off64_t 45239268Sgonzo#endif 46239268Sgonzo 47239268Sgonzo#ifdef _G_NEED_STDARG_H 48239268Sgonzo/* This define avoids name pollution if we're using GNU stdarg.h */ 49249265Sglebius# define __need___va_list 50266277Sian# include <stdarg.h> 51239268Sgonzo# ifdef __GNUC_VA_LIST 52249265Sglebius# undef _IO_va_list 53249265Sglebius# define _IO_va_list __gnuc_va_list 54239268Sgonzo# endif /* __GNUC_VA_LIST */ 55129198Scognet#endif 56181875Sjhb 57181875Sjhb#ifndef __P 58129198Scognet# if _G_HAVE_SYS_CDEFS 59129198Scognet# include <sys/cdefs.h> 60129198Scognet# else 61129198Scognet# ifdef __STDC__ 62239268Sgonzo# define __P(p) p 63239268Sgonzo# else 64266159Sian# define __P(p) () 65266159Sian# endif 66266159Sian# endif 67266159Sian#endif /*!__P*/ 68266159Sian 69266159Sian#ifndef __PMT 70266159Sian# ifdef __STDC__ 71266159Sian# define __PMT(p) p 72266159Sian# else 73266159Sian# define __PMT(p) () 74266159Sian# endif 75266159Sian#endif /*!__P*/ 76266159Sian 77266159Sian/* For backward compatibility */ 78266159Sian#ifndef _PARAMS 79239268Sgonzo# define _PARAMS(protos) __P(protos) 80266159Sian#endif /*!_PARAMS*/ 81129198Scognet 82266159Sian#ifndef __STDC__ 83266159Sian# define const 84239268Sgonzo#endif 85167429Salc#define _IO_UNIFIED_JUMPTABLES 1 86239268Sgonzo#if !_G_HAVE_PRINTF_FP 87266159Sian# define _IO_USE_DTOA 1 88239268Sgonzo#endif 89239268Sgonzo 90266159Sian#ifndef EOF 91239268Sgonzo# define EOF (-1) 92239268Sgonzo#endif 93266159Sian#ifndef NULL 94239268Sgonzo# if defined __GNUG__ && \ 95239268Sgonzo (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) 96239268Sgonzo# define NULL (__null) 97239268Sgonzo# else 98239268Sgonzo# if !defined(__cplusplus) 99239268Sgonzo# define NULL ((void*)0) 100239268Sgonzo# else 101239268Sgonzo# define NULL (0) 102239268Sgonzo# endif 103239268Sgonzo# endif 104239268Sgonzo#endif 105239268Sgonzo 106239268Sgonzo#define _IOS_INPUT 1 107239268Sgonzo#define _IOS_OUTPUT 2 108239268Sgonzo#define _IOS_ATEND 4 109266159Sian#define _IOS_APPEND 8 110266159Sian#define _IOS_TRUNC 16 111266159Sian#define _IOS_NOCREATE 32 112239268Sgonzo#define _IOS_NOREPLACE 64 113239268Sgonzo#define _IOS_BIN 128 114239268Sgonzo 115239268Sgonzo/* Magic numbers and bits for the _flags field. 116239268Sgonzo The magic numbers use the high-order bits of _flags; 117239268Sgonzo the remaining bits are available for variable flags. 118170388Sjeff Note: The magic numbers must all be negative if stdio 119245202Scognet emulation is desired. */ 120245202Scognet 121129198Scognet#define _IO_MAGIC 0xFBAD0000 /* Magic number */ 122239268Sgonzo#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */ 123129198Scognet#define _IO_MAGIC_MASK 0xFFFF0000 124129198Scognet#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */ 125129198Scognet#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 138#define _IO_BAD_SEEN 0x4000 139#define _IO_USER_LOCK 0x8000 140 141/* These are "formatting flags" matching the iostream fmtflags enum values. */ 142#define _IO_SKIPWS 01 143#define _IO_LEFT 02 144#define _IO_RIGHT 04 145#define _IO_INTERNAL 010 146#define _IO_DEC 020 147#define _IO_OCT 040 148#define _IO_HEX 0100 149#define _IO_SHOWBASE 0200 150#define _IO_SHOWPOINT 0400 151#define _IO_UPPERCASE 01000 152#define _IO_SHOWPOS 02000 153#define _IO_SCIENTIFIC 04000 154#define _IO_FIXED 010000 155#define _IO_UNITBUF 020000 156#define _IO_STDIO 040000 157#define _IO_DONT_CLOSE 0100000 158#define _IO_BOOLALPHA 0200000 159 160 161struct _IO_jump_t; struct _IO_FILE; 162 163/* Handle lock. */ 164#ifdef _IO_MTSAFE_IO 165# if defined __GLIBC__ && (__GLIBC__ >= 2 || __GLIBC__ <= -2) 166# if __GLIBC_MINOR__ > 0 167# include <bits/stdio-lock.h> 168# else 169# include <stdio-lock.h> 170# endif 171# define _IO_LOCK_T _IO_lock_t * 172# else 173/*# include <comthread.h>*/ 174# endif 175#else 176# if defined __GLIBC__ && (__GLIBC__ >= 2 || __GLIBC__ <= -2) 177 typedef void _IO_lock_t; 178# define _IO_LOCK_T void * 179# else 180# ifdef __linux__ 181 struct _IO_lock_t { void *ptr; short int field1; short int field2; }; 182# define _IO_LOCK_T struct _IO_lock_t 183# else 184 typedef void _IO_lock_t; 185# endif 186# endif 187#endif 188 189 190/* A streammarker remembers a position in a buffer. */ 191 192struct _IO_marker { 193 struct _IO_marker *_next; 194 struct _IO_FILE *_sbuf; 195 /* If _pos >= 0 196 it points to _buf->Gbase()+_pos. FIXME comment */ 197 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */ 198 int _pos; 199#if 0 200 void set_streampos(streampos sp) { _spos = sp; } 201 void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); } 202 public: 203 streammarker(streambuf *sb); 204 ~streammarker(); 205 int saving() { return _spos == -2; } 206 int delta(streammarker&); 207 int delta(); 208#endif 209}; 210 211struct _IO_FILE { 212 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ 213#define _IO_file_flags _flags 214 215 /* The following pointers correspond to the C++ streambuf protocol. */ 216 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */ 217 char* _IO_read_ptr; /* Current read pointer */ 218 char* _IO_read_end; /* End of get area. */ 219 char* _IO_read_base; /* Start of putback+get area. */ 220 char* _IO_write_base; /* Start of put area. */ 221 char* _IO_write_ptr; /* Current put pointer. */ 222 char* _IO_write_end; /* End of put area. */ 223 char* _IO_buf_base; /* Start of reserve area. */ 224 char* _IO_buf_end; /* End of reserve area. */ 225 /* The following fields are used to support backing up and undo. */ 226 char *_IO_save_base; /* Pointer to start of non-current get area. */ 227 char *_IO_backup_base; /* Pointer to first valid character of backup area */ 228 char *_IO_save_end; /* Pointer to end of non-current get area. */ 229 230 struct _IO_marker *_markers; 231 232 struct _IO_FILE *_chain; 233 234 int _fileno; 235 int _blksize; 236#ifdef _G_IO_IO_FILE_VERSION 237 _IO_off_t _old_offset; 238#else 239 _IO_off_t _offset; 240#endif 241 242#define __HAVE_COLUMN /* temporary */ 243 /* 1+column number of pbase(); 0 is unknown. */ 244 unsigned short _cur_column; 245 char _unused; 246 char _shortbuf[1]; 247 248 /* char* _save_gptr; char* _save_egptr; */ 249 250#ifdef _IO_LOCK_T 251 _IO_LOCK_T _lock; 252#endif 253#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 254 _IO_off64_t _offset; 255 int _unused2[16]; /* Make sure we don't get into trouble again. */ 256#endif 257}; 258 259#ifndef __cplusplus 260typedef struct _IO_FILE _IO_FILE; 261#endif 262 263#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 264#define _IO_stdin_ _IO_2_1_stdin_ 265#define _IO_stdout_ _IO_2_1_stdout_ 266#define _IO_stderr_ _IO_2_1_stderr_ 267#endif 268 269struct _IO_FILE_plus; 270extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_; 271#define _IO_stdin ((_IO_FILE*)(&_IO_stdin_)) 272#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_)) 273#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_)) 274 275 276/* Define the user-visible type, with user-friendly member names. */ 277typedef struct 278{ 279 _IO_ssize_t (*read) __PMT ((struct _IO_FILE *, void *, _IO_ssize_t)); 280 _IO_ssize_t (*write) __PMT ((struct _IO_FILE *, const void *, _IO_ssize_t)); 281 _IO_off_t (*seek) __PMT ((struct _IO_FILE *, _IO_off_t, int)); 282 int (*close) __PMT ((struct _IO_FILE *)); 283} _IO_cookie_io_functions_t; 284 285/* Special file type for fopencookie function. */ 286struct _IO_cookie_file 287{ 288 struct _IO_FILE file; 289 const void *vtable; 290 void *cookie; 291 _IO_cookie_io_functions_t io_functions; 292}; 293 294 295#ifdef __cplusplus 296extern "C" { 297#endif 298 299extern int __underflow __P ((_IO_FILE *)); 300extern int __uflow __P ((_IO_FILE *)); 301extern int __overflow __P ((_IO_FILE *, int)); 302 303#define _IO_getc_unlocked(_fp) \ 304 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \ 305 : *(unsigned char *) (_fp)->_IO_read_ptr++) 306#define _IO_peekc_unlocked(_fp) \ 307 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \ 308 && __underflow (_fp) == EOF ? EOF \ 309 : *(unsigned char *) (_fp)->_IO_read_ptr) 310 311#define _IO_putc_unlocked(_ch, _fp) \ 312 (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \ 313 ? __overflow (_fp, (unsigned char) (_ch)) \ 314 : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch))) 315 316#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0) 317#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0) 318 319extern int _IO_getc __P ((_IO_FILE *__fp)); 320extern int _IO_putc __P ((int __c, _IO_FILE *__fp)); 321extern int _IO_feof __P ((_IO_FILE *__fp)); 322extern int _IO_ferror __P ((_IO_FILE *__fp)); 323 324extern int _IO_peekc_locked __P ((_IO_FILE *__fp)); 325 326/* This one is for Emacs. */ 327#define _IO_PENDING_OUTPUT_COUNT(_fp) \ 328 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) 329 330extern void _IO_flockfile __P ((_IO_FILE *)); 331extern void _IO_funlockfile __P ((_IO_FILE *)); 332extern int _IO_ftrylockfile __P ((_IO_FILE *)); 333 334#ifdef _IO_MTSAFE_IO 335# define _IO_peekc(_fp) _IO_peekc_locked (_fp) 336#else 337# define _IO_peekc(_fp) _IO_peekc_unlocked (_fp) 338# define _IO_flockfile(_fp) /**/ 339# define _IO_funlockfile(_fp) /**/ 340# define _IO_ftrylockfile(_fp) /**/ 341# define _IO_cleanup_region_start(_fct, _fp) /**/ 342# define _IO_cleanup_region_end(_Doit) /**/ 343#endif /* !_IO_MTSAFE_IO */ 344 345 346extern int _IO_vfscanf __P ((_IO_FILE *, const char *, _IO_va_list, int *)); 347extern int _IO_vfprintf __P ((_IO_FILE *, const char *, _IO_va_list)); 348extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t)); 349extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t)); 350 351#if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001 352extern _IO_off64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); 353extern _IO_off64_t _IO_seekpos __P ((_IO_FILE *, _IO_off64_t, int)); 354#else 355extern _IO_off_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int)); 356extern _IO_off_t _IO_seekpos __P ((_IO_FILE *, _IO_off_t, int)); 357#endif 358 359extern void _IO_free_backup_area __P ((_IO_FILE *)); 360 361#ifdef __cplusplus 362} 363#endif 364 365#endif /* _IO_STDIO_H */ 366