home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / support / include / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  6.4 KB  |  219 lines

  1. /* This is part of the iostream/stdio library, providing -*- C -*- I/O.
  2.    Define ANSI C stdio on top of C++ iostreams.
  3.    Copyright (C) 1991 Per Bothner.
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10.  
  11. This library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. Library General Public License for more details.
  15.  
  16. You should have received a copy of the GNU Library General Public
  17. License along with this library; if not, write to the Free
  18. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _STDIO_H
  21. #define _STDIO_H
  22. #define _STDIO_USES_IOSTREAM
  23.  
  24. #ifndef NULL
  25. #if !defined(__cplusplus) || defined(__GNUC__)
  26. #define NULL ((void*)0)
  27. #else
  28. #define NULL (0)
  29. #endif
  30. #endif
  31.  
  32. #ifndef EOF
  33. #define EOF (-1)
  34. #endif
  35. #ifndef BUFSIZ
  36. #define BUFSIZ 1024
  37. #endif
  38.  
  39. #define _IOFBF 0 /* Fully buffered. */
  40. #define _IOLBF 1 /* Line buffered. */
  41. #define _IONBF 2 /* No buffering. */
  42.  
  43. #define SEEK_SET 0
  44. #define SEEK_CUR 1
  45. #define SEEK_END 2
  46.  
  47. #include <_G_config.h>
  48. #ifdef _G_NEED_STDARG_H
  49. #include <stdarg.h>
  50. #endif
  51.  
  52.  /* define size_t.  Crud in case <sys/types.h> has defined it. */
  53. #if !defined(_SIZE_T) && !defined(_T_SIZE_) && !defined(_T_SIZE)
  54. #if !defined(__SIZE_T) && !defined(_SIZE_T_) && !defined(___int_size_t_h)
  55. #if !defined(_GCC_SIZE_T) && !defined(_SIZET_)
  56. #define _SIZE_T
  57. #define _T_SIZE_
  58. #define _T_SIZE
  59. #define __SIZE_T
  60. #ifndef amiga
  61. #define _SIZE_T_
  62. #endif
  63. #define ___int_size_t_h
  64. #define _GCC_SIZE_T
  65. #define _SIZET_
  66. typedef _G_size_t size_t;
  67. #endif
  68. #endif
  69. #endif
  70.  
  71. #ifndef fpos_t
  72. #define fpos_t _G_fpos_t
  73. #endif
  74.  
  75. #define FOPEN_MAX     _G_FOPEN_MAX
  76. #define FILENAME_MAX _G_FILENAME_MAX
  77. #define TMP_MAX 999 /* Only limited by filename length */
  78.  
  79. #define L_ctermid     9
  80. #define L_cuserid     9
  81. #ifdef amiga
  82. #define P_tmpdir      "T:"
  83. #else
  84. #define P_tmpdir      "/tmp"
  85. #endif
  86. #define L_tmpnam      20
  87.  
  88. struct __FILE {
  89.     /* NOTE: Must match (or be a prefix of) __streambuf! */
  90.     int _flags;        /* High-order word is _IO_MAGIC; rest is flags. */
  91.     char* _gptr;    /* Current get pointer */
  92.     char* _egptr;    /* End of get area. */
  93.     char* _eback;    /* Start of putback+get area. */
  94.     char* _pbase;    /* Start of put area. */
  95.     char* _pptr;    /* Current put pointer. */
  96.     char* _epptr;    /* End of put area. */
  97.     char* _base;    /* Start of reserve area. */
  98.     char* _ebuf;    /* End of reserve area. */
  99.     struct streambuf *_chain;
  100. };
  101.  
  102. typedef struct __FILE FILE;
  103.  
  104. #ifndef amiga
  105. /* For use by debuggers. These are linked in if printf or fprintf are used. */
  106. extern FILE *stdin, *stdout, *stderr;
  107. #endif
  108.  
  109. #ifdef amiga
  110. #ifdef __cplusplus
  111. #include <fstream.h>
  112. extern filebuf cin_fb, cout_fb, cerr_fb;
  113. #else
  114. extern struct _fake_filebuf cin_fb, cout_fb, cerr_fb;
  115. #endif
  116. #define stdin ((FILE*)&cin_fb)
  117. #define stdout ((FILE*)&cout_fb)
  118. #define stderr ((FILE*)&cerr_fb)
  119. #else
  120. extern struct _fake_filebuf __std_filebuf_0, __std_filebuf_1, __std_filebuf_2;
  121. #define stdin ((FILE*)&__std_filebuf_0)
  122. #define stdout ((FILE*)&__std_filebuf_1)
  123. #define stderr ((FILE*)&__std_filebuf_2)
  124. #endif
  125.  
  126. #define getc(fp) \
  127.    ((fp)->_gptr >= (fp)->_egptr \
  128.       && __underflow((struct streambuf*)(fp)) == EOF ? EOF \
  129.    : *(unsigned char*)(fp)->_gptr++)
  130. #define putc(c, fp) \
  131.    (((fp)->_pptr >= (fp)->_epptr) ? __overflow((struct streambuf*)(fp), (unsigned char)c) \
  132.    : (unsigned char)(*(fp)->_pptr++ = c))
  133. #define putchar(c) putc(c, stdout)
  134. #define getchar() getc(stdin)
  135.  
  136. #ifdef __cplusplus
  137. extern "C" {
  138. #endif
  139.  
  140. #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
  141. #define _ARGS(args) args
  142. #else
  143. #define _ARGS(args) ()
  144. #endif
  145.  
  146. extern void clearerr _ARGS((FILE*));
  147. extern int fclose _ARGS((FILE*));
  148. extern int feof _ARGS((FILE*));
  149. extern int ferror _ARGS((FILE*));
  150. extern int fflush _ARGS((FILE*));
  151. extern int fgetc _ARGS((FILE *));
  152. extern int fgetpos _ARGS((FILE* fp, fpos_t *pos));
  153. extern char* fgets _ARGS((char*, int, FILE*));
  154. extern FILE* fopen _ARGS((const char*, const char*));
  155. extern int fprintf _ARGS((FILE*, const char* format, ...));
  156. extern int fputc _ARGS((int, FILE*));
  157. extern int fputs _ARGS((const char *str, FILE *fp));
  158. extern size_t fread _ARGS((void*, size_t, size_t, FILE*));
  159. extern FILE* freopen _ARGS((const char*, const char*, FILE*));
  160. extern int fscanf _ARGS((FILE *fp, const char* format, ...));
  161. extern int fseek _ARGS((FILE* fp, long int offset, int whence));
  162. extern int fsetpos _ARGS((FILE* fp, const fpos_t *pos));
  163. extern long int ftell _ARGS((FILE* fp));
  164. extern size_t fwrite _ARGS((const void*, size_t, size_t, FILE*));
  165. extern char* gets _ARGS((char*));
  166. extern void perror _ARGS((const char *));
  167. #ifdef amiga
  168. extern int printf_gcc _ARGS((const char* format, ...));
  169. #else
  170. extern int printf_gcc _ARGS((const char* format, ...));
  171. #endif
  172. extern int puts _ARGS((const char *str));
  173. extern int remove _ARGS((const char*));
  174. extern int rename _ARGS((const char* _old, const char* _new));
  175. extern void rewind _ARGS((FILE*));
  176. extern int scanf _ARGS((const char* format, ...));
  177. extern void setbuf _ARGS((FILE*, char*));
  178. extern void setlinebuf _ARGS((FILE*));
  179. extern void setbuffer _ARGS((FILE*, char*, int));
  180. extern int setvbuf _ARGS((FILE*, char*, int mode, size_t size));
  181. #ifdef amiga
  182. extern int sprintf_gcc _ARGS((char*, const char* format, ...));
  183. #else
  184. extern int sprintf _ARGS((char*, const char* format, ...));
  185. #endif
  186. extern int sscanf _ARGS((const char* string, const char* format, ...));
  187. extern FILE* tmpfile _ARGS((void));
  188. extern char* tmpnam _ARGS((char*));
  189. extern int ungetc _ARGS((int c, FILE* fp));
  190. extern int vfprintf _ARGS((FILE *fp, char const *fmt0, _G_va_list));
  191. extern int vprintf _ARGS((char const *fmt, _G_va_list));
  192. extern int vsprintf _ARGS((char* string, const char* format, _G_va_list));
  193.  
  194. #if !defined(__STRICT_ANSI__) || defined(_POSIX_SOURCE)
  195. extern FILE *fdopen _ARGS((int, const char *));
  196. extern int fileno _ARGS((FILE*));
  197.  
  198. #ifndef amiga     /* we don't support popen and pclose (yet) */
  199. extern FILE* popen _ARGS((const char*, const char*));
  200. extern int pclose _ARGS((FILE*));
  201. #endif
  202.  
  203. #endif
  204.  
  205. extern int __underflow _ARGS((struct streambuf*));
  206. extern int __overflow _ARGS((struct streambuf*, int));
  207.  
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211.  
  212. #ifdef amiga
  213. /* if we use iostreams, we have to use (s)printf from iostreams/stdio !*/
  214. #define sprintf sprintf_gcc
  215. #define printf printf_gcc
  216. #endif
  217.  
  218. #endif /*!_STDIO_H*/
  219.