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