home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / Project / include / stdclib / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-17  |  7.3 KB  |  291 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     stdio.h
  4.     Standard input and output.
  5.  
  6.     Copyright Apple Computer,Inc.  1995
  7.     All rights reserved
  8.  
  9. ************************************************************/
  10.  
  11.  
  12. #ifndef __STDIO__
  13. #define __STDIO__
  14.  
  15. #define __cstdio__
  16. /*
  17.  * Include common declarations 
  18.  */
  19.  
  20. #include <NullDef.h>
  21. #include <SizeTDef.h>
  22. #include <SeekDefs.h>
  23. #include <VaListTDef.h>
  24.  
  25.  
  26. /*
  27.  *  The basic data structure for a stream is the FILE type.
  28.  */
  29.  
  30. #ifdef powerc
  31. #pragma options align=power
  32. #endif
  33. struct FILE {
  34.     int             _cnt;
  35.     unsigned char   *_ptr;
  36.     unsigned char   *_base;
  37.     unsigned char   *_end;
  38.     unsigned short  _size;
  39.     unsigned short  _flag;
  40.     unsigned short  _file;
  41. };
  42. #ifdef powerc
  43. #pragma options align=reset
  44. #endif
  45.  
  46. typedef struct FILE FILE;
  47.  
  48.  
  49. /*
  50.  *  The type to uniquely specify the position in a file, returned by fgetpos().
  51.  */
  52.  
  53. typedef long fpos_t;
  54.  
  55.  
  56. /*
  57.  *  Values for various bits of a FILE's _flag field.
  58.  *  The values _IOFBF, _IOLBF, and _IONBF can be used as the
  59.  *  third argument to setvbuf();
  60.  */
  61.  
  62. #define _IOFBF      0x00    /* File is fully buffered       */
  63. #define _IOREAD     0x01    /* File is open for Reading     */
  64. #define _IOWRT      0x02    /* File is open for Writing    */
  65. #define _IONBF      0x04    /* File I/O is unbuffered       */
  66. #define _IOMYBUF    0x08    /* Buffer allocated by stdio    */
  67. #define _IOEOF      0x10    /* End of file reached          */
  68. #define _IOERR      0x20    /* I/O error has occurred       */
  69. #define _IOLBF      0x40    /* File is line buffered        */
  70. #define _IORW       0x80    /* File is open for Read/Write  */
  71. #define _IOSYNC    0x100    /* Flush output on Read         */
  72. #define _IOBINARY  0x200    /* For backward compatibility   */
  73. #define _IOBACK   0x4000    /* For backward compatibility   */
  74.  
  75.  
  76. /*
  77.  *  The default buffer sizes for a fully buffered or line buffered file.
  78.  */
  79.  
  80. #define BUFSIZ    1024
  81. #define _LBFSIZ    254
  82.  
  83.  
  84. /*
  85.  *  The normal end-of-file indicator.
  86.  */
  87.  
  88. #define EOF       (-1)
  89.  
  90.  
  91. /*
  92.  *  FOPEN_MAX is the minimum number of files that a program is guaranteed to be able
  93.  *  to have open simultaneously (including the pre-opened stdin, stdout, and stderr).
  94.  *  The numbers are listed in Inside Macintosh, page IV-178, as:
  95.  *  64K ROM, 128K Macintosh     12 files
  96.  *  64K ROM, 512K Macintosh     40 files
  97.  *  128K ROM                    40 files per volume
  98.  *
  99.  *  FILENAME_MAX is the maximum length of a file name, including a trailing zero byte.
  100.  */
  101.  
  102. #define FOPEN_MAX      12
  103. #define FILENAME_MAX   32
  104.  
  105.  
  106. /*
  107.  *  L_tmpnam is the size of char array long enough to hold a temporary file name
  108.  *  generated by tmpnam(), including the trailing null byte.  The name is in the
  109.  *  form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  110.  *  ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  111.  *  of digits, all determined at runtime.
  112.  */
  113.  
  114. #define L_tmpnam       14
  115.  
  116.  
  117. /*
  118.  *  TMP_MAX is the number of distinct file names that tmpnam() can generate.
  119.  */
  120.  
  121. #define TMP_MAX     17576
  122.  
  123.  
  124. /*
  125.  *  The standard predefined streams: error, input, and output
  126.  */
  127.  
  128. #define stdin        (&_iob[0])
  129. #define stdout       (&_iob[1])
  130. #define stderr       (&_iob[2])
  131.  
  132.  
  133. #ifdef __cplusplus
  134. extern "C" {
  135. #endif
  136.  
  137. #if defined (__powerc) || defined (powerc) || defined (__CFM68K__)
  138.     #pragma import on
  139. #endif
  140.  
  141. /*
  142.  * Operations on Files
  143.  */
  144.  
  145. extern int remove (const char *filename);
  146. extern int rename (const char *oldname, const char *newname);
  147. extern FILE *tmpfile (void);
  148. extern char *tmpnam (char *s);
  149.  
  150.  
  151. /*
  152.  * File Access Functions
  153.  */
  154.  
  155. extern int fclose (FILE *stream);
  156. extern int fflush (FILE *stream);
  157. extern FILE *fopen (const char *filename, const char *mode);
  158. extern FILE *freopen (const char *filename, const char *mode, FILE *stream);
  159. extern void setbuf (FILE *stream, char *buf);
  160. extern int setvbuf (FILE *stream, char *buf, int mode, size_t size);
  161.  
  162.  
  163. /*
  164.  * Formatted Input/Output Functions
  165.  */
  166.  
  167. extern int fprintf (FILE *stream, const char *format, ...);
  168. extern int fscanf (FILE *stream, const char *format, ...);
  169. extern int printf (const char *format, ...);
  170. extern int scanf (const char *format, ...);
  171. extern int sprintf (char *s, const char *format, ...);
  172. extern int sscanf (const char *s, const char *format, ...);
  173. extern int vfprintf (FILE *stream, const char *format, va_list arg);
  174. extern int vprintf (const char *format, va_list arg);
  175. extern int vsprintf (char *s, const char *format, va_list arg);
  176.  
  177.  
  178. /*
  179.  * Character Input/Output Functions
  180.  */
  181.  
  182. extern int fgetc (FILE *stream);
  183. extern char *fgets (char *s, int n, FILE *stream);
  184. extern int fputc (int c, FILE *stream);
  185. extern int fputs (const char *s, FILE *stream);
  186. extern int getc (FILE *stream);
  187. extern int getchar (void);
  188. extern char *gets (char *s);
  189. extern int putc (int c, FILE *stream);
  190. extern int putchar (int c);
  191. extern int puts (const char *s);
  192. extern int ungetc (int c, FILE *stream);
  193.  
  194. /*
  195.  * WARNING!!
  196.  *
  197.  * These macros evaluate their arguments more than once.
  198.  * Be sure that evaluation of the "s" argument has no side effects.
  199.  *
  200.  * For example, using "getc(mychar++)" would cause "mychar" to be
  201.  * incremented twice.
  202.  *
  203.  * To avoid this, either assign "mychar" to a temporary, or put the
  204.  * function name in paranthesis, so that the macro is not envoked:
  205.  *    "(getc)(mychar++)"
  206.  *
  207.  */
  208.  
  209. #define getc(s) (--(s)->_cnt >= 0 ? (int) *(s)->_ptr++ : _filbuf(s))
  210. #define getchar() (getc(stdin))
  211. #define putc(c, s)  (--(s)->_cnt >= 0 ?  \
  212.                         ((int) (*(s)->_ptr++ = (unsigned char) (c))) : \
  213.                         _flsbuf((unsigned char) (c), (s)))
  214. #define putchar(c) (putc((c), stdout))
  215.  
  216.  
  217. /*
  218.  * Direct Input/Output Functions
  219.  */
  220.  
  221. extern size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream);
  222. extern size_t fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream);
  223.  
  224.  
  225. /*
  226.  * File Positioning Functions
  227.  */
  228.  
  229. extern int fgetpos (FILE *stream, fpos_t *pos);
  230. extern int fseek (FILE *stream, long int offset, int whence);
  231. extern int fsetpos (FILE *stream, const fpos_t *pos);
  232. extern long int ftell (FILE *stream);
  233. extern void rewind (FILE *stream);
  234.  
  235.  
  236. /*
  237.  * Error Handling Functions
  238.  */
  239.  
  240. extern void clearerr (FILE *stream);
  241. extern int feof (FILE *stream);
  242. extern int ferror (FILE *stream);
  243. extern void perror (const char *s);
  244.  
  245. #define clearerr(s) ((void)((s)->_flag &= ~(_IOERR | _IOEOF)))
  246. #define feof(s) ((s)->_flag & _IOEOF)
  247. #define ferror(s) ((s)->_flag & _IOERR)
  248.  
  249.  
  250. /*
  251.  * Internal structures exposed by previous macro definitions.
  252.  */
  253.  
  254. extern FILE _iob[];    /* Array of FILE control blocks. */
  255. #define _NFILE 40      /* Size of _iob. */
  256.  
  257. extern int _filbuf(FILE *);
  258. extern int _flsbuf(unsigned char, FILE *);
  259.  
  260.  
  261. /*
  262.  *  Non-ANSI extensions
  263.  *
  264.  * The prefered mechanism for enabling these is by defining __useAppleExts__.  
  265.  * In the absence of this symbol, the __STDC__ symbol is used to enable or
  266.  * disable these extentions.
  267.  */
  268.  
  269. #if defined (__useAppleExts__) || \
  270.      (defined (applec) && ! defined (__STDC__)) || \
  271.      (defined (__PPCC__) && __STDC__ == 0)
  272.  
  273. #define fileno(p)  (p)->_file
  274.  
  275. extern FILE *fdopen(int fildes, const char *mode);
  276. extern void fsetfileinfo (const char *filename, unsigned long newcreator, unsigned long newtype);
  277. extern int getw(FILE *stream);
  278. extern int putw(int w, FILE *stream);
  279.  
  280. #endif
  281.  
  282. #if defined (__powerc) || defined (powerc) || defined (__CFM68K__)
  283.     #pragma import off
  284. #endif
  285.  
  286. #ifdef __cplusplus
  287. }
  288. #endif
  289.  
  290. #endif  /* __STDIO__ */
  291.