home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gpincl07.lzh / GPINCL07 / STDIO.H < prev    next >
C/C++ Source or Header  |  1993-07-24  |  14KB  |  558 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. /*
  20.  *  Please check the following before installing this file:
  21.  *
  22.  *  Make sure USG is #defined if you are on a USG system!
  23.  *
  24.  *  Check the value of _NFILE against the one in your /usr/include/stdio.h.
  25.  *  (USG only)
  26.  *
  27.  *  Check whether your libc.a sprintf function returns
  28.  *  an int (as do most) versus a char* (BSD), and (un)comment
  29.  *  the corresponding SPRINTF_RETURNS_INT line.
  30.  *
  31.  *  Check the value of BUFSIZ against the one in your /usr/include/stdio.h.
  32.  *
  33.  *  Carefully check the fields and order of _iobuf declaration against
  34.  *  the one in your /usr/include/stdio.h. Xenix-based systems
  35.  *  may need some re-ordering of _iobuf. fields.
  36.  *
  37.  *  Note that some _IOXXX #defines may not be present in your 
  38.  *  /usr/include/stdio.h. This is ok, so long as the ones that
  39.  *  are present in both are set to the same values.
  40.  *
  41.  *  Some of the prototypes refer to functions that may not be
  42.  *  present in your libc.a. This is ok so long as you do not
  43.  *  actually call such functions.
  44.  *
  45.  */
  46.  
  47. #ifndef _stdio_h
  48. #ifdef __GNUG__
  49. /* #pragma once */
  50. #pragma interface
  51. #endif
  52. #define _stdio_h 1
  53.  
  54. /*
  55.    HAVE_VPRINTF should be set if vprintf is in libc.a
  56.    HAVE_SETVBUF should be set if setvbuf is in libc.a
  57.    HAVE_SETLINEBUF should be set if setlinebuf in libc.a
  58.  
  59.    The following are probably correct for the listed systems
  60.  
  61. */
  62.  
  63. #ifdef SYSTEM_FIVE
  64. #define USG
  65. #endif
  66.  
  67. #if defined(USG)
  68. #define  HAVE_VPRINTF
  69. #define  HAVE_SETVBUF  
  70. //#define  HAVE_SETLINEBUF
  71.  
  72. #elif defined(VMS)
  73. #define  HAVE_VPRINTF
  74. #define  HAVE_SETVBUF  
  75. //#define  HAVE_SETLINEBUF
  76. #define NO_LIBGXX_MALLOC
  77. #define _NFILE 20
  78. #define IOBUF_FLAG_TYPE char
  79. #define IOBUF_BUFSIZ_FIELD    /* we aint got one either*/
  80.  
  81. #elif masscomp
  82. #ifndef _NFILE
  83. #define _NFILE 40
  84. #endif
  85. #ifdef _ATT
  86. #define HAVE_VPRINTF
  87. #define HAVE_SETVBUF  
  88. #define USG
  89. #endif
  90. #ifdef _UCB
  91. #undef HAVE_VPRINTF
  92. #undef HAVE_SETLINEBUF
  93. #define IOBUF_BUFSIZ_FIELD
  94. #endif
  95.  
  96. #elif defined(vax) || defined(sony)
  97. //#define HAVE_VPRINTF
  98. //#define  HAVE_SETVBUF  
  99. #define HAVE_SETLINEBUF
  100.  
  101. #elif defined(sun)
  102. #define  HAVE_VPRINTF
  103. #define  HAVE_SETVBUF  
  104. #define  HAVE_SETLINEBUF
  105.  
  106. #elif defined(sequent)
  107. //#define  HAVE_VPRINTF
  108. //#define  HAVE_SETVBUF  
  109. #define  HAVE_SETLINEBUF
  110.  
  111. #elif defined(DGUX)
  112. #define HAVE_VPRINTF
  113. #define HAVE_SETVBUF
  114. #define HAVE_SETLINEBUF
  115. #define IOBUF_FLAG_TYPE    int
  116. #define IOBUF_FILE_TYPE    int
  117. #define _NFILE 64
  118. #define IOBUF_EXTRA_FIELDS    int _reserve[27];
  119. #define SPRINTF_RETURNS_INT
  120. #define BUFEND_ENTRY_TYPE unsigned char *
  121. #define USG
  122.  
  123. #elif defined(TEKTRONIX_SYSV) || defined(hp9000s300) || defined(i386)
  124. #define  HAVE_VPRINTF
  125. #define  HAVE_SETVBUF  
  126. //#define HAVE_SETLINEBUF
  127. #define  USG
  128.  
  129. #elif defined(convex)
  130. //#define HAVE_VPRINTF
  131. //#define HAVE_SETVBUF
  132. #define HAVE_SETLINEBUF
  133. #define IOBUF_FILE_TYPE unsigned char
  134. #define HAVE_VOID_DOPRNT
  135.  
  136. #elif defined(atarist)
  137. #include <compiler.h>
  138.  
  139. #ifndef _SIZE_T
  140. #define _SIZE_T __SIZE_TYPEDEF__
  141. typedef _SIZE_T size_t;
  142. #endif
  143.  
  144. /* object of type capable of recording uniquely every position in a file */
  145. typedef unsigned long fpos_t;
  146.  
  147. #define HAVE_VSCANF
  148. #define HAVE_VPRINTF
  149. #define HAVE_SETVBUF
  150. #define HAVE_SETLINEBUF
  151. #define IOBUF_FLAG_TYPE unsigned int
  152. #define IOBUF_FILE_TYPE int
  153. #define IOBUF_BUFSIZ_FIELD long _bsiz;
  154. #define IOBUF_EXTRA_FIELDS unsigned char _ch;
  155. #define _NFILE (20)
  156. #define SPRINTF_RETURNS_INT
  157. #ifndef NULL
  158. #  ifdef __MSHORT__
  159. #    define __NULL ((void *)0)
  160. #  else
  161.      /* avoid complaints about misuse of NULL :-)*/
  162. #    define __NULL (0)
  163. #  endif
  164. #endif
  165. #define L_tmpnam    128
  166. #define TMP_MAX        100
  167. #ifndef NO_LIBGXX_MALLOC
  168. #  define NO_LIBGXX_MALLOC
  169. #endif
  170.  
  171. #endif /* atarist */
  172.  
  173. #ifdef hpux
  174. #define IOBUF_FLAG_TYPE short
  175. #endif
  176.  
  177. #ifdef i386
  178. #define IOBUF_FLAG_TYPE char
  179. #endif
  180.  
  181. #ifdef USG
  182. #define IOBUF_BUFSIZ_FIELD    /* System V ain't got one */
  183. #endif
  184.  
  185. /* Some default definitions for things not defined machine-specifically
  186.    above.  */
  187.  
  188. #ifndef IOBUF_BUFSIZ_FIELD
  189. #define IOBUF_BUFSIZ_FIELD int _bufsiz;
  190. #endif
  191.  
  192. #ifndef IOBUF_FLAG_TYPE
  193. #define IOBUF_FLAG_TYPE short
  194. #endif
  195.  
  196. #ifndef IOBUF_FILE_TYPE
  197. #define IOBUF_FILE_TYPE char
  198. #endif
  199.  
  200. #ifndef IOBUF_EXTRA_FIELDS
  201. #define IOBUF_EXTRA_FIELDS
  202. #endif
  203.  
  204. #if defined(USG) && !defined(_NFILE)
  205. #ifdef hpux
  206. #define _NFILE 60
  207. #elif
  208. #define _NFILE 20
  209. #endif
  210. #endif
  211.  
  212. #ifdef USG
  213. #define _bufend(p) _bufendtab[(p)->_file]
  214. #define _bufsiz(p) (_bufend(p) - (p)->_base)
  215. #ifndef BUFEND_ENTRY_TYPE
  216. #define BUFEND_ENTRY_TYPE char *
  217. #endif
  218. extern "C" {
  219. BUFEND_ENTRY_TYPE _bufendtab[];
  220. }
  221. #endif
  222.  
  223. /* check this -- hardly any systems need this these days */
  224. /* #define SPRINTF_RETURNS_INT */
  225.  
  226. /* check and possibly redefine the following */
  227.  
  228. #ifndef VMS
  229. #define BUFSIZ  ((size_t)1024)
  230. #else
  231. #define BUFSIZ 512
  232. #endif
  233.  
  234. #ifdef masscomp 
  235. extern struct _iobuf {
  236. #ifdef BUFSIZ
  237. #  undef BUFSIZ
  238. #endif
  239. #define BUFSIZ  4096
  240.  
  241. #ifdef mc68000
  242.     unsigned char*    _ptr;
  243.     int      _cnt;
  244. #endif
  245.     char*    _base;
  246.     IOBUF_BUFSIZ_FIELD
  247.     IOBUF_FLAG_TYPE    _flag;
  248.     IOBUF_FILE_TYPE    _file;
  249.     IOBUF_EXTRA_FIELDS
  250. } _iob[];
  251. #else /* not masscomp */
  252. #ifdef atarist
  253. #  ifdef BUFSIZ
  254. #    undef BUFSIZ
  255. #  endif
  256. #  define BUFSIZ ((size_t)1024)
  257. extern "C" { extern unsigned long __DEFAULT_BUFSIZ__; }
  258. extern  struct  _iobuf {
  259.     long                _cnt;
  260.     unsigned char      *_ptr;
  261.     unsigned char      *_base;
  262.     IOBUF_FLAG_TYPE    _flag;
  263.     IOBUF_FILE_TYPE    _file;
  264.     IOBUF_BUFSIZ_FIELD
  265.     IOBUF_EXTRA_FIELDS
  266. } _iob[];
  267. #else /* not atarist */
  268. extern  struct  _iobuf {
  269.     int      _cnt;
  270.     char*    _ptr;
  271.     char*    _base;
  272.     IOBUF_BUFSIZ_FIELD
  273.     IOBUF_FLAG_TYPE    _flag;
  274.     IOBUF_FILE_TYPE    _file;
  275.     IOBUF_EXTRA_FIELDS
  276. } _iob[];
  277. #endif /* not atari */
  278. #endif /* not masscomp */
  279.  
  280. #ifndef VMS
  281. typedef struct _iobuf FILE;
  282. #else
  283. typedef struct _iobuf *FILE;
  284. typedef FILE *VMS_FILE;
  285. #endif
  286.  
  287. #ifndef atarist
  288. #define _IOFBF    00000
  289. #define _IOREAD   00001
  290. #define _IOWRT    00002
  291. #define _IONBF    00004
  292. #define _IOMYBUF  00010
  293. #define _IOEOF    00020
  294. #define _IOERR    00040
  295. #if defined(USG) && !defined(hpux)
  296. #define _IOSTRG   00000  /* faked out for USG */
  297. #define _IOLBF    00100
  298. #define _IORW     00200
  299. #define _IOAPPEND 00000 /* faked out for USG */
  300. #elif defined(masscomp)
  301. #define _IOSTRG        0x00        /* not used in this version of stdio */
  302. #ifdef _IOERR
  303. # undef _IOERR
  304. #endif
  305. #define    _IOERR        0x40        /* i/o error on buffer */
  306. #define    _IOLBF        0x80        /* buffering is by line */
  307. #define    _IORW        0x100        /* read or write ok */
  308. #define _IOAPPEND    0x00        /* not used in this version of stdio */
  309. #elif defined(hpux)
  310. #define _IOSTRG   00000  /* faked out for USG */
  311. #define _IOLBF    00200
  312. #define _IORW     00400
  313. #define _IOAPPEND 00000 /* faked out for USG */
  314. #elif defined(VMS)
  315. #define    _IOSTRG        0100            /* Doing I/O to a string */
  316. #define    _IORW        0200            /* Open for read/write     */
  317. #define _IOAPPEND    00        /* VMS does not actually have this */
  318. #else
  319. #define _IOSTRG   00100
  320. #define _IOLBF    00200
  321. #define _IORW     00400
  322. #define _IOAPPEND 01000
  323. #endif
  324. #ifdef DGUX
  325. #define _IOPBF    00400  /* Boolean - ungetc() not called since fill/flush */
  326. #endif
  327. #else /* atarist */
  328. #define    _IOREAD        0x0001        /* file may be read from */
  329. #define    _IOWRT        0x0002        /* file may be written to */
  330. #define    _IOBIN        0x0004        /* file is in "binary" mode */
  331. #define    _IODEV        0x0008        /* file is a character device */
  332. #define    _IORW        0x0080        /* file is open for update (r+w) */
  333. #define    _IOFBF        0x0100        /* i/o is fully buffered */
  334. #define    _IOLBF        0x0200        /* i/o is line buffered */
  335. #define    _IONBF        0x0400        /* i/o is not buffered */
  336. #define    _IOMYBUF    0x0800        /* standard buffer */
  337. #define    _IOEOF        0x1000        /* EOF has been reached */
  338. #define    _IOERR        0x4000        /* an error has occured */
  339. #define _IOSTRING    0x8000        /* really a string buffer   */
  340. #define    _IOSTRG        _IOSTRING
  341. #define _IOAPPEND    0        /* fake */
  342. #endif /* atarist */
  343.  
  344. #define EOF       (-1)
  345.  
  346. #ifndef NULL
  347. #define NULL      0
  348. #endif
  349.  
  350. #ifndef VMS
  351. #define stdin     (&_iob[0])
  352. #define stdout    (&_iob[1])
  353. #define stderr    (&_iob[2])
  354.  
  355. #ifndef atarist
  356. #define getc(p) (--(p)->_cnt>=0?(int)(*(unsigned char*)(p)->_ptr++):_filbuf(p))
  357. #define putc(x,p) (--(p)->_cnt>=0? ((int)((unsigned char)((*(p)->_ptr++=(unsigned)(x))))):_flsbuf((unsigned)(x),p))
  358. #else
  359. #define getc    fgetc
  360. #define putc    fputc
  361. #define ungetc  fungetc
  362. #define ungetchar(c) fungetc((c), stdin)
  363. #endif
  364.  
  365. #ifdef atarist
  366. #define clearerr(p) ((void) ((p)->_flag &= ~(_IOERR|_IOEOF)))
  367. #else
  368. #define clearerr(p) ((p)->_flag &= ~(_IOERR|_IOEOF))
  369. #endif
  370. #define getchar()   getc(stdin)
  371. #define putchar(x)  putc(x,stdout)
  372. #define feof(p)     (((p)->_flag&_IOEOF)!=0)
  373. #define ferror(p)   (((p)->_flag&_IOERR)!=0)
  374. #define fileno(p)   ((p)->_file)
  375.  
  376. #else
  377.  
  378. #undef _IOFBF
  379. #define _IOLBF 1
  380. #define _IOFBF 2
  381. #define F_RDLCK
  382. /*    Also, stdin/stdout/stderr need to be defined
  383.  *    [We also use a hack here that makes the GCC assembler modify
  384.  *     the psect attributes to match those of the VAX-11 "C" runtime]
  385.  */
  386. #define    stdin    $$PsectAttributes_NOSHR$$stdin
  387. #define    stdout    $$PsectAttributes_NOSHR$$stdout
  388. #define    stderr    $$PsectAttributes_NOSHR$$stderr
  389.  
  390. extern VMS_FILE stdin;
  391. extern VMS_FILE stdout;
  392. extern VMS_FILE stderr;
  393.  
  394. //     Define the stdio macros
  395.  
  396. #define getc(p)        fgetc(p)
  397. #define getchar()    fgetc(stdin)
  398. #define putc(x,p)    fputc(x,p)
  399. #define putchar(x)    fputc(x,stdout)
  400. #define feof(p)        (((*p)->_flag&_IOEOF)!=0)
  401. #define ferror(p)    (((*p)->_flag&_IOERR)!=0)
  402. #define fileno(p)    ((*p)->_file)
  403. #define clearerr(p)    ((*p)->_flag &= ~(_IOERR|_IOEOF))
  404.  
  405. #endif
  406.  
  407. extern "C" {
  408.  
  409. #ifndef atarist
  410. #ifdef VMS
  411. int     c$$doprint(const char*, void*, FILE*);
  412. int     c$$doscan(FILE*, const char*, ...);
  413. int    c$$filbuf(FILE*);
  414. int    c$$flsbuf(unsigned, FILE*);
  415. #else
  416. int    _doprnt(const char*, void*, FILE*);
  417. int    _doscan(FILE*, const char*, ...);
  418. int    _filbuf(FILE*);
  419. int    _flsbuf(unsigned, FILE*);
  420. #endif
  421. int    fclose(FILE*);
  422. FILE*  fdopen(int, const char*);
  423. int    fflush(FILE*);
  424. int    fgetc(FILE*);
  425. char*  fgets(char*, int, FILE *);
  426. FILE*  fopen(const char*, const char*);
  427. int    fprintf(FILE*, const char* ...);
  428. int    fputc(int, FILE*);
  429. int    fputs(const char*, FILE*);
  430. int    fread(void*, int, int, FILE*);
  431. #ifdef VMS
  432. FILE*  freopen(const char*, const char*, FILE* ...);
  433. #else
  434. FILE*  freopen(const char*, const char*, FILE*);
  435. #endif
  436. int    fscanf(FILE*, const char* ...);
  437. int    fseek(FILE*, long, int);
  438. long   ftell(FILE *);
  439. int    fwrite(const void*, int, int, FILE*);
  440. char*  gets(char*);
  441. int    getw(FILE*);
  442. int    pclose(FILE*);
  443. FILE*  popen(const char*, const char*);
  444. int    printf(const char* ...);
  445. int    puts(const char*);
  446. int    putw(int, FILE*);
  447. int    rewind(FILE*);
  448. int    scanf(const char* ...);
  449. int    setbuf(FILE*, char*);
  450. int    setbuffer(FILE*, char*, int);
  451. int    setlinebuf(FILE*);
  452. int    setvbuf(FILE*, char*, int, int);
  453. int    sscanf(char*, const char* ...);
  454. FILE*  tmpfile();
  455. int    ungetc(int, FILE*);
  456. int    vfprintf(FILE*, const char*, ...);
  457.  
  458. // Third arg to vprintf must be '...' for some machines, & doesn't
  459. // hurt for others.
  460.  
  461. int    vprintf(const char*, ... );
  462.  
  463. #ifdef SPRINTF_RETURNS_INT
  464. int    sprintf(char*, const char* ...);
  465. int    vsprintf(char*, const char*, ...);
  466. #else
  467. char*  sprintf(char*, const char* ...);
  468. char*  vsprintf(char*, const char*, ...);
  469. #endif
  470.  
  471. #else /* atarist */
  472. int remove (const char *filename);
  473. int rename (const char *_oldname, const char *_newname);
  474.  
  475. FILE *tmpfile (void);
  476. char *tmpnam (char *buf);
  477.  
  478. int fclose (FILE *fp);
  479. int fflush (FILE *fp);
  480.  
  481. FILE *fopen (const char *filename, const char *mode);
  482. FILE *freopen (const char *filename, const char *mode, FILE *fp);
  483.  
  484. void setbuf (FILE *fp, char *buf);
  485. int setvbuf (FILE *fp, char *bp, int bmode, size_t size);
  486.  
  487. int fprintf (FILE *fp, const char *fmt, ...);
  488. int printf (const char *fmt, ...);
  489. int sprintf (char *buf, const char *fmt, ...);
  490.  
  491. int fscanf (FILE *fp, const char *fmt, ...);
  492. int scanf (const char *fmt, ...);
  493. int sscanf (const char *buf, const char *fmt, ...);
  494.  
  495. int vfprintf (FILE *, const char *, __VA_LIST__);
  496. int vprintf (const char *, __VA_LIST__);
  497. int vsprintf (char *, const char *, __VA_LIST__);
  498.  
  499. int vfscanf (FILE *, const char *, __VA_LIST__);
  500. int vscanf  (const char *, __VA_LIST__);
  501. int vsscanf (const char *, const char *, __VA_LIST__);
  502.  
  503. int fgetc (FILE *fp);
  504. char *fgets (char *data, int limit, FILE *fp);
  505. char *gets (char *data);
  506.  
  507. int fputc (int c, FILE *fp);
  508. int fputs (const char *data, FILE *fp);
  509. int puts (const char *data);
  510. int fungetc (int c, FILE *fp);
  511.  
  512. size_t fread (void *data, size_t size, size_t count, FILE *fp);
  513. size_t fwrite (const void *data, size_t size, size_t count, FILE *fp);
  514.  
  515. int fgetpos (FILE *fp, fpos_t *pos);
  516. int fsetpos (FILE *fp, fpos_t *pos);
  517.  
  518. long ftell (FILE *fp);
  519. void rewind (FILE *fp);
  520. int fseek (FILE *fp, long offset, int origin);
  521.  
  522. void perror (const char *msg);
  523.  
  524. #ifndef __STRICT_ANSI__
  525. FILE *fdopen (int h, const char *mode);
  526. FILE *popen (const char *command, const char *type);
  527. int pclose (FILE *fp);
  528. # ifndef _POSIX_SOURCE
  529. void _binmode (int force);
  530. long getl (FILE *fp);
  531. long putl (long n, FILE *fp);
  532.  
  533. short getw (FILE *fp);
  534. short putw (short n, FILE *fp);
  535. #endif
  536. #endif
  537. int _filbuf (FILE *);    /* needed for getc */
  538. #endif /* atarist */
  539.  
  540. }
  541.  
  542. #ifndef L_ctermid
  543. #define L_ctermid    9 
  544. #endif
  545. #ifndef L_cuserid
  546. #define L_cuserid    9
  547. #endif
  548. #ifndef P_tmpdir
  549. #define    P_tmpdir    "/tmp/"
  550. #endif
  551. #ifndef L_tmpnam
  552. #define    L_tmpnam    (sizeof(P_tmpdir) + 15)
  553. #endif
  554.  
  555. extern FILE* log_file;
  556.  
  557. #endif // _stdio_h
  558.