1: /* 2: * Copyright (c) 1990 The Regents of the University of California. 3: * All rights reserved. 4: * 5: * Redistribution and use in source and binary forms are permitted 6: * provided that the above copyright notice and this paragraph are 7: * duplicated in all such forms and that any documentation, 8: * advertising materials, and other materials related to such 9: * distribution and use acknowledge that the software was developed 10: * by the University of California, Berkeley. The name of the 11: * University may not be used to endorse or promote products derived 12: * from this software without specific prior written permission. 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16: * 17: * @(#)stdio.h 5.3 (Berkeley) 3/15/86 18: */ 19: 20: /* 21: * NB: to fit things in six character monocase externals, the 22: * stdio code uses the prefix `__s' for stdio objects, typically 23: * followed by a three-character attempt at a mnemonic. 24: */ 25: 26: #ifndef _STDIO_H_ 27: #define _STDIO_H_ 28: 29: #include "_ansi.h" 30: 31: #define _FSTDIO /* ``function stdio'' */ 32: 33: #define __need_size_t 34: #include <stddef.h> 35: 36: #define __need___va_list 37: #include <stdarg.h> 38: 39: /* 40: * <sys/reent.h> defines __FILE, _fpos_t. 41: * They must be defined there because struct _reent needs them (and we don't 42: * want reent.h to include this file. 43: */ 44: 45: #include <sys/reent.h> 46: #include <sys/types.h> 47: 48: _BEGIN_STD_C 49: 50: typedef __FILE FILE; 51: 52: #ifdef __CYGWIN__ 53: #ifdef __CYGWIN_USE_BIG_TYPES__ 54: typedef _fpos64_t fpos_t; 55: #else 56: typedef _fpos_t fpos_t; 57: #endif 58: #else 59: typedef _fpos_t fpos_t; 60: #ifdef __LARGE64_FILES 61: typedef _fpos64_t fpos64_t; 62: #endif 63: #endif /* !__CYGWIN__ */ 64: 65: #include <sys/stdio.h> 66: 67: #define __SLBF 0x0001 /* line buffered */ 68: #define __SNBF 0x0002 /* unbuffered */ 69: #define __SRD 0x0004 /* OK to read */ 70: #define __SWR 0x0008 /* OK to write */ 71: /* RD and WR are never simultaneously asserted */ 72: #define __SRW 0x0010 /* open for reading & writing */ 73: #define __SEOF 0x0020 /* found EOF */ 74: #define __SERR 0x0040 /* found error */ 75: #define __SMBF 0x0080 /* _buf is from malloc */ 76: #define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */ 77: #define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 78: #define __SOPT 0x0400 /* do fseek() optimisation */ 79: #define __SNPT 0x0800 /* do not do fseek() optimisation */ 80: #define __SOFF 0x1000 /* set iff _offset is in fact correct */ 81: #define __SMOD 0x2000 /* true => fgetline modified _p text */ 82: #if defined(__CYGWIN__) 83: # define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */ 84: #endif 85: #define __SL64 0x8000 /* is 64-bit offset large file */ 86: 87: /* 88: * The following three definitions are for ANSI C, which took them 89: * from System V, which stupidly took internal interface macros and 90: * made them official arguments to setvbuf(), without renaming them. 91: * Hence, these ugly _IOxxx names are *supposed* to appear in user code. 92: * 93: * Although these happen to match their counterparts above, the 94: * implementation does not rely on that (so these could be renumbered). 95: */ 96: #define _IOFBF 0 /* setvbuf should set fully buffered */ 97: #define _IOLBF 1 /* setvbuf should set line buffered */ 98: #define _IONBF 2 /* setvbuf should set unbuffered */ 99: 100: #ifndef NULL 101: #define NULL 0 102: #endif 103: 104: #define EOF (-1) 105: 106: #ifdef __BUFSIZ__ 107: #define BUFSIZ __BUFSIZ__ 108: #else 109: #define BUFSIZ 1024 110: #endif 111: 112: #ifdef __FOPEN_MAX__ 113: #define FOPEN_MAX __FOPEN_MAX__ 114: #else 115: #define FOPEN_MAX 20 116: #endif 117: 118: #ifdef __FILENAME_MAX__ 119: #define FILENAME_MAX __FILENAME_MAX__ 120: #else 121: #define FILENAME_MAX 1024 122: #endif 123: 124: #ifdef __L_tmpnam__ 125: #define L_tmpnam __L_tmpnam__ 126: #else 127: #define L_tmpnam FILENAME_MAX 128: #endif 129: 130: #ifndef __STRICT_ANSI__ 131: #define P_tmpdir "/tmp" 132: #endif 133: 134: #ifndef SEEK_SET 135: #define SEEK_SET 0 /* set file offset to offset */ 136: #endif 137: #ifndef SEEK_CUR 138: #define SEEK_CUR 1 /* set file offset to current plus offset */ 139: #endif 140: #ifndef SEEK_END 141: #define SEEK_END 2 /* set file offset to EOF plus offset */ 142: #endif 143: 144: #define TMP_MAX 26 145: 146: #ifndef _REENT_ONLY 147: #define stdin (_REENT->_stdin) 148: #define stdout (_REENT->_stdout) 149: #define stderr (_REENT->_stderr) 150: #else /* _REENT_ONLY */ 151: #define stdin (_impure_ptr->_stdin) 152: #define stdout (_impure_ptr->_stdout) 153: #define stderr (_impure_ptr->_stderr) 154: #endif /* _REENT_ONLY */ 155: 156: #define _stdin_r(x) ((x)->_stdin) 157: #define _stdout_r(x) ((x)->_stdout) 158: #define _stderr_r(x) ((x)->_stderr) 159: 160: /* 161: * Functions defined in ANSI C standard. 162: */ 163: 164: #ifdef __GNUC__ 165: #define __VALIST __gnuc_va_list 166: #else 167: #define __VALIST char* 168: #endif 169: 170: FILE * _EXFUN(tmpfile, (void)); 171: char * _EXFUN(tmpnam, (char *)); 172: int _EXFUN(fclose, (FILE *)); 173: int _EXFUN(fflush, (FILE *)); 174: FILE * _EXFUN(freopen, (const char *, const char *, FILE *)); 175: void _EXFUN(setbuf, (FILE *, char *)); 176: int _EXFUN(setvbuf, (FILE *, char *, int, size_t)); 177: int _EXFUN(fprintf, (FILE *, const char *, ...)); 178: int _EXFUN(fscanf, (FILE *, const char *, ...)); 179: int _EXFUN(printf, (const char *, ...)); 180: int _EXFUN(scanf, (const char *, ...)); 181: int _EXFUN(sscanf, (const char *, const char *, ...)); 182: int _EXFUN(vfprintf, (FILE *, const char *, __VALIST)); 183: int _EXFUN(vprintf, (const char *, __VALIST)); 184: int _EXFUN(vsprintf, (char *, const char *, __VALIST)); 185: int _EXFUN(fgetc, (FILE *)); 186: char * _EXFUN(fgets, (char *, int, FILE *)); 187: int _EXFUN(fputc, (int, FILE *)); 188: int _EXFUN(fputs, (const char *, FILE *)); 189: int _EXFUN(getc, (FILE *)); 190: int _EXFUN(getchar, (void)); 191: char * _EXFUN(gets, (char *)); 192: int _EXFUN(putc, (int, FILE *)); 193: int _EXFUN(putchar, (int)); 194: int _EXFUN(puts, (const char *)); 195: int _EXFUN(ungetc, (int, FILE *)); 196: size_t _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *)); 197: size_t _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *)); 198: #ifdef _COMPILING_NEWLIB 199: int _EXFUN(fgetpos, (FILE *, _fpos_t *)); 200: #else 201: int _EXFUN(fgetpos, (FILE *, fpos_t *)); 202: #endif 203: int _EXFUN(fseek, (FILE *, long, int)); 204: #ifdef _COMPILING_NEWLIB 205: int _EXFUN(fsetpos, (FILE *, const _fpos_t *)); 206: #else 207: int _EXFUN(fsetpos, (FILE *, const fpos_t *)); 208: #endif 209: long _EXFUN(ftell, ( FILE *)); 210: void _EXFUN(rewind, (FILE *)); 211: void _EXFUN(clearerr, (FILE *)); 212: int _EXFUN(feof, (FILE *)); 213: int _EXFUN(ferror, (FILE *)); 214: void _EXFUN(perror, (const char *)); 215: #ifndef _REENT_ONLY 216: FILE * _EXFUN(fopen, (const char *_name, const char *_type)); 217: int _EXFUN(sprintf, (char *, const char *, ...)); 218: int _EXFUN(remove, (const char *)); 219: int _EXFUN(rename, (const char *, const char *)); 220: #endif 221: #ifndef __STRICT_ANSI__ 222: int _EXFUN(asprintf, (char **, const char *, ...)); 223: #ifdef _COMPILING_NEWLIB 224: int _EXFUN(fseeko, (FILE *, _off_t, int)); 225: _off_t _EXFUN(ftello, ( FILE *)); 226: #else 227: int _EXFUN(fseeko, (FILE *, off_t, int)); 228: off_t _EXFUN(ftello, ( FILE *)); 229: #endif 230: int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST)); 231: int _EXFUN(iprintf, (const char *, ...)); 232: int _EXFUN(fiprintf, (FILE *, const char *, ...)); 233: int _EXFUN(siprintf, (char *, const char *, ...)); 234: char * _EXFUN(tempnam, (const char *, const char *)); 235: int _EXFUN(vasprintf, (char **, const char *, __VALIST)); 236: int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST)); 237: int _EXFUN(vfscanf, (FILE *, const char *, __VALIST)); 238: int _EXFUN(vscanf, (const char *, __VALIST)); 239: int _EXFUN(vsscanf, (const char *, const char *, __VALIST)); 240: #ifndef _REENT_ONLY 241: int _EXFUN(fcloseall, (_VOID)); 242: int _EXFUN(snprintf, (char *, size_t, const char *, ...)); 243: #endif 244: #endif 245: 246: /* 247: * Routines in POSIX 1003.1. 248: */ 249: 250: #ifndef __STRICT_ANSI__ 251: #ifndef _REENT_ONLY 252: FILE * _EXFUN(fdopen, (int, const char *)); 253: #endif 254: int _EXFUN(fileno, (FILE *)); 255: int _EXFUN(getw, (FILE *)); 256: int _EXFUN(pclose, (FILE *)); 257: FILE * _EXFUN(popen, (const char *, const char *)); 258: int _EXFUN(putw, (int, FILE *)); 259: void _EXFUN(setbuffer, (FILE *, char *, int)); 260: int _EXFUN(setlinebuf, (FILE *)); 261: int _EXFUN(getc_unlocked, (FILE *)); 262: int _EXFUN(getchar_unlocked, (void)); 263: void _EXFUN(flockfile, (FILE *)); 264: int _EXFUN(ftrylockfile, (FILE *)); 265: void _EXFUN(funlockfile, (FILE *)); 266: int _EXFUN(putc_unlocked, (int, FILE *)); 267: int _EXFUN(putchar_unlocked, (int)); 268: #endif 269: 270: /* 271: * Recursive versions of the above. 272: */ 273: 274: int _EXFUN(_asprintf_r, (struct _reent *, char **, const char *, ...)); 275: int _EXFUN(_fcloseall_r, (struct _reent *)); 276: FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *)); 277: FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *)); 278: int _EXFUN(_fclose_r, (struct _reent *, FILE *)); 279: int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...)); 280: int _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int)); 281: long _EXFUN(_ftell_r, (struct _reent *, FILE *)); 282: int _EXFUN(_getchar_r, (struct _reent *)); 283: char * _EXFUN(_gets_r, (struct _reent *, char *)); 284: int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...)); 285: int _EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...)); 286: int _EXFUN(_mkstemp_r, (struct _reent *, char *)); 287: char * _EXFUN(_mktemp_r, (struct _reent *, char *)); 288: void _EXFUN(_perror_r, (struct _reent *, const char *)); 289: int _EXFUN(_printf_r, (struct _reent *, const char *, ...)); 290: int _EXFUN(_putchar_r, (struct _reent *, int)); 291: int _EXFUN(_puts_r, (struct _reent *, const char *)); 292: int _EXFUN(_remove_r, (struct _reent *, const char *)); 293: int _EXFUN(_rename_r, (struct _reent *, 294: const char *_old, const char *_new)); 295: int _EXFUN(_scanf_r, (struct _reent *, const char *, ...)); 296: int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...)); 297: int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...)); 298: int _EXFUN(_sscanf_r, (struct _reent *, const char *, const char *, ...)); 299: char * _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *)); 300: FILE * _EXFUN(_tmpfile_r, (struct _reent *)); 301: char * _EXFUN(_tmpnam_r, (struct _reent *, char *)); 302: int _EXFUN(_ungetc_r, (struct _reent *, int, FILE *)); 303: int _EXFUN(_vasprintf_r, (struct _reent *, char **, const char *, __VALIST)); 304: int _EXFUN(_vfiprintf_r, (struct _reent *, FILE *, const char *, __VALIST)); 305: int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST)); 306: int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST)); 307: int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST)); 308: int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST)); 309: int _EXFUN(_vfscanf_r, (struct _reent *, FILE *, const char *, __VALIST)); 310: int _EXFUN(_vscanf_r, (struct _reent *, const char *, __VALIST)); 311: int _EXFUN(_vsscanf_r, (struct _reent *, const char *, const char *, __VALIST)); 312: 313: ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *)); 314: ssize_t _EXFUN(__getline, (char **, size_t *, FILE *)); 315: 316: #ifdef __LARGE64_FILES 317: #if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB) 318: FILE * _EXFUN(fdopen64, (int, const char *)); 319: FILE * _EXFUN(fopen64, (const char *, const char *)); 320: _off64_t _EXFUN(ftello64, (FILE *)); 321: _off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int)); 322: int _EXFUN(fgetpos64, (FILE *, _fpos64_t *)); 323: int _EXFUN(fsetpos64, (FILE *, const _fpos64_t *)); 324: FILE * _EXFUN(tmpfile64, (void)); 325: 326: FILE * _EXFUN(_fdopen64_r, (struct _reent *, int, const char *)); 327: FILE * _EXFUN(_fopen64_r, (struct _reent *,const char *, const char *)); 328: _off64_t _EXFUN(_ftello64_r, (struct _reent *, FILE *)); 329: _off64_t _EXFUN(_fseeko64_r, (struct _reent *, FILE *, _off64_t, int)); 330: int _EXFUN(_fgetpos64_r, (struct _reent *, FILE *, _fpos64_t *)); 331: int _EXFUN(_fsetpos64_r, (struct _reent *, FILE *, const _fpos64_t *)); 332: FILE * _EXFUN(_tmpfile64_r, (struct _reent *)); 333: #endif /* !__CYGWIN__ */ 334: #endif /* __LARGE64_FILES */ 335: 336: /* 337: * Routines internal to the implementation. 338: */ 339: 340: int _EXFUN(__srget, (FILE *)); 341: int _EXFUN(__swbuf, (int, FILE *)); 342: 343: /* 344: * Stdio function-access interface. 345: */ 346: 347: #ifndef __STRICT_ANSI__ 348: FILE *_EXFUN(funopen,(const _PTR _cookie, 349: int (*readfn)(_PTR _cookie, char *_buf, int _n), 350: int (*writefn)(_PTR _cookie, const char *_buf, int _n), 351: fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence), 352: int (*closefn)(_PTR _cookie))); 353: 354: #define fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0) 355: #define fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0) 356: #endif 357: 358: /* 359: * The __sfoo macros are here so that we can 360: * define function versions in the C library. 361: */ 362: #define __sgetc_raw(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 363: 364: #ifdef __SCLE 365: static __inline__ int __sgetc(FILE *__p) 366: { 367: int __c = __sgetc_raw(__p); 368: if ((__p->_flags & __SCLE) && (__c == '\r')) 369: { 370: int __c2 = __sgetc_raw(__p); 371: if (__c2 == '\n') 372: __c = __c2; 373: else 374: ungetc(__c2, __p); 375: } 376: return __c; 377: } 378: #else 379: #define __sgetc(p) __sgetc_raw(p) 380: #endif 381: 382: #ifdef _never /* __GNUC__ */ 383: /* If this inline is actually used, then systems using coff debugging 384: info get hopelessly confused. 21sept93 rich@cygnus.com. */ 385: static __inline int __sputc(int _c, FILE *_p) { 386: if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 387: return (*_p->_p++ = _c); 388: else 389: return (__swbuf(_c, _p)); 390: } 391: #else 392: /* 393: * This has been tuned to generate reasonable code on the vax using pcc 394: */ 395: #define __sputc_raw(c, p) \ 396: (--(p)->_w < 0 ? \ 397: (p)->_w >= (p)->_lbfsize ? \ 398: (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 399: (int)*(p)->_p++ : \ 400: __swbuf('\n', p) : \ 401: __swbuf((int)(c), p) : \ 402: (*(p)->_p = (c), (int)*(p)->_p++)) 403: #ifdef __SCLE 404: #define __sputc(c, p) \ 405: ((((p)->_flags & __SCLE) && ((c) == '\n')) \ 406: ? __sputc_raw('\r', (p)) : 0 , \ 407: __sputc_raw((c), (p))) 408: #else 409: #define __sputc(c, p) __sputc_raw(c, p) 410: #endif 411: #endif 412: 413: #define __sfeof(p) (((p)->_flags & __SEOF) != 0) 414: #define __sferror(p) (((p)->_flags & __SERR) != 0) 415: #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 416: #define __sfileno(p) ((p)->_file) 417: 418: #define feof(p) __sfeof(p) 419: #define ferror(p) __sferror(p) 420: #define clearerr(p) __sclearerr(p) 421: 422: #if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */ 423: #define fileno(p) __sfileno(p) 424: #endif 425: 426: #ifndef __CYGWIN__ 427: #ifndef lint 428: #define getc(fp) __sgetc(fp) 429: #define putc(x, fp) __sputc(x, fp) 430: #endif /* lint */ 431: #endif /* __CYGWIN__ */ 432: 433: #define getchar() getc(stdin) 434: #define putchar(x) putc(x, stdout) 435: 436: #ifndef __STRICT_ANSI__ 437: /* fast always-buffered version, true iff error */ 438: #define fast_putc(x,p) (--(p)->_w < 0 ? \ 439: __swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0)) 440: 441: #define L_cuserid 9 /* posix says it goes in stdio.h :( */ 442: #ifdef __CYGWIN__ 443: #define L_ctermid 16 444: #endif 445: #endif 446: 447: _END_STD_C 448: 449: #endif /* _STDIO_H_ */ 450: