home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 May: Tool Chest / Apple_Developer_CD_Series_May_1994_Tool_Chest.iso / Tool Chest / Interfaces / Universal Interfaces / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-10  |  6.1 KB  |  277 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     stdio.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1993.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14.  
  15. #ifndef __STDIO__
  16. #define __STDIO__
  17.  
  18. #ifndef NULL
  19. #define NULL 0
  20. #endif
  21.  
  22. #ifndef __size_t__
  23. #define __size_t__
  24. #ifdef powerc
  25. typedef unsigned long size_t;
  26. #else
  27. typedef unsigned int size_t;
  28. #endif /* powerc */
  29. #endif
  30.  
  31. #ifndef __va_list__
  32. #define __va_list__
  33. typedef char *va_list;
  34. #endif
  35.  
  36.  
  37. /*
  38.  *    The basic data structure for a stream is the FILE.
  39.  */
  40.  
  41. #ifdef powerc
  42. #pragma options align=power
  43. #endif
  44. typedef struct {
  45.     int             _cnt;
  46.     unsigned char    *_ptr;
  47.     unsigned char    *_base;
  48.     unsigned char    *_end;
  49.     unsigned short    _size;
  50.     unsigned short    _flag;
  51.     unsigned short    _file;
  52. } FILE;
  53. #ifdef powerc
  54. #pragma options align=reset
  55. #endif
  56.  
  57.  
  58. /*
  59.  *    fpos_t is a type that can express any position in a file.  A file's
  60.  *    end-of-file marker has type fpos_t.
  61.  */
  62.  
  63. typedef long fpos_t;
  64.  
  65.  
  66. /*
  67.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  68.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  69.  */
  70.  
  71. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  72. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  73. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  74. #define _IONBF        (1<<2)        /* no buffering */
  75. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  76. #define _IOEOF        (1<<4)
  77. #define _IOERR        (1<<5)
  78. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  79. #define _IORW        (1<<7)        /* Enable read/write access */
  80. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  81. #define _IOBINARY    (1<<9)        /* Binary stream */
  82. #define _IOBACK        (1<<14)        /* Result of "ungetc() is in the buffer */ 
  83.  
  84.  
  85. /*
  86.  *    Default file buffer sizes used by setbuf() and setvbuf().
  87.  */
  88.  
  89. #define BUFSIZ    1024            /* default file buffer size */
  90. #define _LBFSIZ  254            /* Line buffer size */
  91.  
  92.  
  93. /*
  94.  *    The standard end-of-file indicator.
  95.  */
  96.  
  97. #define EOF        (-1)
  98.  
  99.  
  100. /*
  101.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  102.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  103.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  104.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  105.  *    of digits, all determined at runtime.
  106.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  107.  */
  108.  
  109. #define L_tmpnam    14
  110. #define TMP_MAX        17576
  111.  
  112.  
  113. /*
  114.  *    The minimum number of files that a program is guaranteed to be able to have
  115.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  116.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  117.  *    64K ROM, 128K Macintosh        12 files
  118.  *    64K ROM, 512K Macintosh        40 files
  119.  *    128K ROM                    40 files per volume
  120.  */
  121.  
  122. #define FOPEN_MAX    12
  123.  
  124.  
  125. /*
  126.  *    Maximum length of a file name, including a trailing zero byte.
  127.  */
  128.  
  129. #define FILENAME_MAX    32
  130.  
  131.  
  132. /*
  133.  *    For use by fseek():
  134.  */
  135.  
  136. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  137.  
  138. #define SEEK_CUR    1
  139. #define SEEK_END    2
  140. #define SEEK_SET    0
  141. #endif
  142.  
  143.  
  144. /*
  145.  *    The standard predefined streams.
  146.  */
  147.  
  148. #define stdin        (&_iob[0])
  149. #define stdout        (&_iob[1])
  150. #define stderr        (&_iob[2])
  151.  
  152.  
  153. #ifdef __cplusplus
  154. extern "C" {
  155. #endif
  156.  
  157. /*
  158.  *    Operations on files
  159.  */
  160.  
  161. int remove(const char *_filename);
  162. int rename(const char *_oldname, const char *_newname);
  163. FILE *tmpfile(void);
  164. char *tmpnam(char *_s);
  165.  
  166.  
  167. /*
  168.  *    File access functions
  169.  */
  170.  
  171. int fclose(FILE *_stream);
  172. int fflush(FILE *_stream);
  173. FILE *fopen(const char *_filename, const char *_mode);
  174. FILE *freopen(const char *_filename, const char *_mode, FILE *_stream);
  175. void setbuf(FILE *_stream, char *_buf);
  176. int setvbuf(FILE *_stream, char *_buf, int _mode, size_t _size);
  177.  
  178.  
  179. /*
  180.  *    Formatted input/output functions
  181.  */
  182.  
  183. int fprintf(FILE *_stream, const char *_format, ...);
  184. int fscanf(FILE *_stream, const char *_format, ...);
  185. int printf(const char *_format, ...);
  186. int scanf(const char *_format, ...);
  187. int sprintf(char *s, const char *_format, ...);
  188. int sscanf(const char *s, const char *_format, ...);
  189. int vfprintf(FILE *_stream, const char *_format, va_list arg);
  190. int vprintf(const char *_format, va_list arg);
  191. int vsprintf(char *s, const char *_format, va_list arg);
  192.  
  193.  
  194. /*
  195.  *    Character input/output functions and macros
  196.  */
  197.  
  198. int fgetc(FILE *_stream);
  199. char *fgets(char *s, int n, FILE *_stream);
  200. int fputc(int c, FILE *_stream);
  201. int fputs(const char *s, FILE *_stream);
  202. int getc(FILE *_stream);
  203. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  204. int getchar(void);
  205. #define getchar()    getc(stdin)
  206. char *gets(char *s);
  207. int putc(int c, FILE *_stream);
  208. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  209.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  210.                         _flsbuf((unsigned char) (x), (p)))
  211. int putchar(int c);
  212. #define putchar(x)    putc((x), stdout)
  213. int puts(const char *s);
  214. int ungetc(int c, FILE *_stream);
  215.  
  216.  
  217. /*
  218.  *    Direct input/output functions
  219.  */
  220.  
  221. size_t fread(void *ptr, size_t _size, size_t _nmemb, FILE *_stream);
  222. size_t fwrite(const void *ptr, size_t _size, size_t _nmemb, FILE *_stream);
  223.  
  224.  
  225. /*
  226.  *    File positioning functions
  227.  */
  228.  
  229. int fgetpos(FILE *_stream, fpos_t *_pos);
  230. int fseek(FILE *_stream, long int _offset, int _whence);
  231. int fsetpos(FILE *_stream, const fpos_t *_pos);
  232. long int ftell(FILE *_stream);
  233. void rewind(FILE *_stream);
  234.  
  235.  
  236. /*
  237.  *    Error-handling functions and macros
  238.  */
  239.  
  240. void clearerr(FILE *_stream);
  241. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  242. int feof(FILE *_stream);
  243. #define feof(p)     ((p)->_flag & _IOEOF)
  244. int ferror(FILE *_stream);
  245. #define ferror(p)    ((p)->_flag & _IOERR)
  246. void perror(const char *_s);
  247.  
  248. /*
  249.  * For macros
  250.  */
  251.  
  252. extern FILE _iob[];
  253. #define _NFILE 20
  254. int _filbuf(FILE *);
  255. int _flsbuf(unsigned char, FILE *);
  256.  
  257. /*
  258.  *    Non-ANSI extensions
  259.  */
  260.  
  261. #if __STDC__ == 0
  262.  
  263. #define fileno(p)    (p)->_file
  264. FILE *fdopen(int fildes, const char *_mode);
  265. void fsetfileinfo (char *_filename, unsigned long _newcreator, unsigned long _newtype);
  266. int getw(FILE *_stream);
  267. int putw(int w, FILE *_stream);
  268.  
  269. #endif
  270.  
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274.  
  275.  
  276. #endif
  277.