home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_clib_h_stdio < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  9.9 KB  |  361 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/clib/h/RCS/stdio,v $
  4.  * $Date: 1996/11/06 22:01:41 $
  5.  * $Revision: 1.3 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: stdio,v $
  10.  * Revision 1.3  1996/11/06 22:01:41  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.2  1996/10/30 21:58:58  unixlib
  14.  * Massive changes made by Nick Burret and Peter Burwood.
  15.  *
  16.  * Revision 1.1  1996/04/19 21:02:57  simon
  17.  * Initial revision
  18.  *
  19.  ***************************************************************************/
  20.  
  21. /* ANSI Standard 4.9: Input/Output <stdio.h>.  */
  22.  
  23. #ifndef __STDIO_H
  24. #define __STDIO_H
  25.  
  26. #ifndef __UNIXLIB_TYPES_H
  27. #include <unixlib/types.h>
  28. #endif
  29. #ifndef __STDARG_H
  30. #include <stdarg.h>
  31. #endif
  32. #ifndef __STDDEF_H
  33. #include <stddef.h>
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. typedef __off_t fpos_t;
  41.  
  42.  
  43. /* Maximum number of files that can be open at once.
  44.    Keep in sync with <limits.h>, _POSIX_OPEN_MAX.  */
  45. #define FOPEN_MAX    64
  46.  
  47. /* Maximum length of a filename.
  48.    Keep in sync with <limits.h>, _POSIX_NAME_MAX.  */
  49. #define FILENAME_MAX    252
  50.  
  51. /* Default buffer size.  */
  52. #define BUFSIZ        4096
  53.  
  54. /* End of file character.  */
  55. #define EOF        (-1)
  56.  
  57. /* The possibilities for the third argument to fseek.
  58.    <unistd.h> has the same definitions.  */
  59.  
  60. /* Seek from beginning of file.  */
  61. #ifndef SEEK_SET
  62. #define SEEK_SET    0
  63. #endif
  64. /* Seek from current position.  */
  65. #ifndef SEEK_CUR
  66. #define SEEK_CUR    1
  67. #endif
  68. /* Seek from end of file.  */
  69. #ifndef SEEK_END
  70. #define SEEK_END    2
  71. #endif
  72.  
  73. /* Magic number to fill __magic.  */
  74. #define _IOMAGIC 0xfedabeeb
  75.  
  76. typedef struct __iobuf
  77.   {
  78.   /* Magic number for stream validation.  */
  79.   int __magic;
  80.   unsigned char *i_ptr;
  81.   unsigned char *i_base;
  82.   int        i_cnt;
  83.   unsigned char *o_ptr;
  84.   unsigned char *o_base;
  85.   int        o_cnt;
  86.   /* File flags.  */
  87.   int        flag;
  88.   /* File descriptor.  */
  89.   int        fd;
  90.   fpos_t    pos;
  91.   int        bufsiz;
  92.   } __FILE;
  93.  
  94. #define FILE __FILE
  95.  
  96. /* Nonzero if stream is a valid stream.  */
  97. #define __validfp(stream) (stream != NULL && stream->__magic == _IOMAGIC)
  98.  
  99. /* Standard streams.  */
  100. extern FILE __iob[FOPEN_MAX];
  101.  
  102. #define stdin        (&__iob[0])
  103. #define stdout        (&__iob[1])
  104. #define stderr        (&__iob[2])
  105.  
  106. #define _IOOMASK    0000003
  107.  
  108. #define _IOREAD     0000001
  109. #define _IOWRITE    0000002
  110. #define _IOAPPEND    0000004
  111.  
  112. #define _IOBF        0000070
  113.  
  114. /* The possibilities for the third argument to setvbuf.  */
  115.  
  116. /* No buffering.  */
  117. #define _IONBF        0000010
  118. /* Line buffering.  */
  119. #define _IOLBF        0000020
  120. /* Full buffering.  */
  121. #define _IOFBF        0000040
  122.  
  123. #define _IOEOF        0000100
  124. #define _IOERR        0000200
  125.  
  126. #define _IOTTY        0000400
  127. #define _IOPIPE     0001000
  128.  
  129. /* Return the EOF indicator for stream.  */
  130. #define feof(f)     ((f)->flag & _IOEOF)
  131. /* Return the error indicator for stream.  */
  132. #define ferror(f)    ((f)->flag & _IOERR)
  133. #define fisatty(f)    ((f)->flag & _IOTTY)
  134. #define fispipe(f)    ((f)->flag & _IOPIPE)
  135. #define fisopen(f)    ((f)->flag & (_IOREAD|_IOWRITE))
  136.  
  137. /* Clear the error and EOF indicators of stream.  */
  138. #define clearerr(stream) (void)((stream)->flag &= (~(_IOEOF|_IOERR)))
  139.  
  140. extern int (feof)(FILE *);
  141. extern int (ferror)(FILE *);
  142. extern int (fisatty)(FILE *);
  143. extern int (fisopen)(FILE *);
  144.  
  145. extern void (clearerr)(FILE *);
  146.  
  147. /* Print a message describing the meaning of the value of errno. */
  148. extern void perror (const char *s);
  149.  
  150. extern void __stdioinit(void);    /* initialise stdin,stdout & stderr */
  151. extern void __stdioexit(void);    /* close streams & delete tmpfile() */
  152.  
  153. /* fill buffer */
  154. extern int __filbuf(FILE *);
  155. /* flush buffer */
  156. extern int __flsbuf(int,FILE *);
  157.  
  158. /* null pointer output */
  159. extern char *__null;
  160.  
  161. /* Open a file and create a new stream for it.  */
  162. extern FILE *fopen (const char *filename, const char *modes);
  163. /* Open a file, replacing an existing stream with it.  */
  164. extern FILE *freopen (const char *filename, const char *modes, FILE *stream);
  165.  
  166. /* Close stream, or all streams if stream is null.  */
  167. extern int fclose (FILE *stream);
  168. /* Flush stream, or all streams if stream is null.  */
  169. extern int fflush (FILE *stream);
  170.  
  171.  
  172.  
  173. /* Read chunks of generic data from stream.  */
  174. extern size_t fread (void *ptr, size_t size, size_t n, FILE *stream);
  175. extern int __fread(FILE *,char *,int);
  176.  
  177. /* Write chunks of generic data to stream.  */
  178. extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
  179. extern int __fwrite(FILE *,char *,int);
  180.  
  181. /* If buf is null, make stream unbuffered.
  182.    If not null, use buffer buf of size BUFSIZ.  */
  183. extern void setbuf (FILE *stream, char *buf);
  184. /* Make stream use buffering mode 'mode'.
  185.    If buf is not NULL, use n bytes of it for buffering;
  186.    else allocate an internal buffer n bytes long.  */
  187. extern int setvbuf (FILE *stream, char *buf, int modes, size_t n);
  188.  
  189. /* Push a character back onto the input buffer of stream.  */
  190. extern int ungetc (int c, FILE *stream);
  191.  
  192. /* Get stream's position.  */
  193. extern int fgetpos (FILE *stream, fpos_t *pos);
  194. /* Set stream's position.  */
  195. extern int fsetpos (FILE *stream, const fpos_t *pos);
  196.  
  197. /* Seek to a certain position on stream.  */
  198. extern int fseek (FILE *stream, long int off, int whence);
  199. /* Return the current position of stream.  */
  200. extern long ftell (FILE *stream);
  201. /* Rewind to the beginning of stream.  */
  202. extern void rewind (FILE *stream);
  203.  
  204. /* Read a character from stream.  */
  205. #define getc(f) \
  206.     ((--((f)->i_cnt) >= 0 ? *((f)->i_ptr)++ : __filbuf(f)))
  207. /* Read a character from stdin.  */
  208. #define getchar()    getc(stdin)
  209.  
  210. /* Read a character from stream.  */
  211. extern int fgetc (FILE *stream);
  212. extern int (getc)(FILE *);
  213. extern int (getchar)(void);
  214.  
  215. /* Write a character to stream. */
  216. #define putc(c,f) \
  217.     (((((f)->flag) & _IOLBF) && (c) == '\n') ? __flsbuf(c,f) : \
  218.     ((--((f)->o_cnt) > 0 ? (*((f)->o_ptr)++ = (c)) : __flsbuf(c,f))))
  219. #define putchar(c)    putc(c,stdout)
  220.  
  221. extern int fputc(int,FILE *);
  222. extern int (putc)(int,FILE *);
  223. extern int (putchar)(int);
  224.  
  225. /* Get a newline-terminated string of finite length from stream.  */
  226. extern char *fgets (char *s, size_t n, FILE *stream);
  227. /* Get a newline-terminated string from stdin, removing the newline.  */
  228. extern char *gets (char *s);
  229.  
  230. /* Write a string to stream.  */
  231. extern int fputs (const char *s, FILE *stream);
  232. /* Write a string, followed by a newline, to stdout.  */
  233. extern int puts (const char *s);
  234.  
  235. /* formatted I/O */
  236.  
  237. extern int __printf(char *,const char *,va_list);
  238. extern int __scanf(FILE *,const char *,va_list,int *);
  239.  
  240. /* buffer for printf */
  241. extern char *__pbuf;
  242. /* buffer for scanf */
  243. extern char *__sbuf;
  244.  
  245. /* I know I said I would not do this, but ... */
  246.  
  247. /* Write formatted output to s from argument list arg.  */
  248. extern int vsprintf (char *s, const char *format, va_list arg);
  249. /* Write formatted output to stream from arg list arg.  */
  250. extern int vfprintf (FILE *stream, const char *format, va_list arg);
  251. /* Write formatted output to stdio from arg list arg.  */
  252. extern int vprintf (const char *format, va_list arg);
  253.  
  254. #pragma -v1
  255. /* Write formatted output to s.  */
  256. extern int sprintf (char *s, const char *format, ...);
  257. /* Write formatted output to stream.  */
  258. extern int fprintf (FILE *stream, const char *format, ...);
  259. /* Write formatted output to stdout.  */
  260. extern int printf (const char *format, ...);
  261.  
  262. #pragma -v2
  263. /* Read formatted input from s.  */
  264. extern int sscanf (const char *s, const char *format, ...);
  265. /* Read formatted input from stream.  */
  266. extern int fscanf (FILE *stream, const char *format, ...);
  267. /* Read format input from stdin.  */
  268. extern int scanf (const char *format, ...);
  269. #pragma -v3
  270.  
  271. /* How long an array of chars must be to be passed to tmpnam.  */
  272. #define L_tmpnam    255
  273. /* The minimum number of unique filenames generated by tmpnam.  */
  274. #define TMP_MAX     0x100
  275.  
  276. /* Remove file filename.  */
  277. extern int remove (const char *filename);
  278.  
  279. /* Rename file oldname to newname.  */
  280. extern int rename(const char *old, const char *newname);
  281.  
  282. /* Create a temporary file and open it read/write.  */
  283. extern FILE *tmpfile (void);
  284. /* Generate a temporary filename.  */
  285. extern char *tmpnam (char *s);
  286.  
  287. /* Generate a unique temporary file name for temp.  */
  288. extern char *mktemp(char *temp);
  289. /* As for mktemp but returns an open file descriptor on the file.  */
  290. extern int mkstemp(char *temp);
  291.  
  292. extern FILE *__tmpf;
  293. extern char __tmpn[L_tmpnam + 1];
  294. extern unsigned int __tmpcnt;
  295.  
  296. #define __STDIOLIB__ static void __stdiolib(void) { __stdioinit(); }
  297.  
  298. /* System V enhancements.  */
  299.  
  300. /* Get a word (int) from stream.  */
  301. extern int getw (FILE *stream);
  302. /* Write a word (int) to stream.  */
  303. extern int putw (int w, FILE *stream);
  304.  
  305. /* Default path prefix for tempnam and tmpnam.  */
  306. #define P_tmpdir "/tmp"
  307.  
  308.  
  309. /* BSD enhancements.  */
  310.  
  311. /* If BUF is NULL, make STREAM unbuffered.
  312.    Else make it use SIZE bytes of BUF for buffering.  */
  313. extern void setbuffer (FILE *stream, char *buf, size_t size);
  314.  
  315. /* Make STREAM line-buffered.  */
  316. extern void setlinebuf (FILE *stream);
  317.  
  318. extern int sys_nerr;
  319. extern char *sys_errlist[];
  320.  
  321. /* POSIX enhancements.  */
  322.  
  323. /* Create a new stream that refers to an existing system file descriptor.  */
  324. extern FILE *fdopen (int fd, const char *modes);
  325.  
  326. /* Return the system file descriptor for stream.  */
  327. #define fileno(f)    ((f)->fd)
  328. extern int (fileno)(FILE *stream);
  329.  
  330. #if 0
  331. /* Return the name of the controlling terminal.  */
  332. extern char *ctermid (char *__s);
  333. /* Return the name of the current user.  */
  334. extern char *cuserid (char *__s);
  335. #endif
  336.  
  337. /* POSIX 2 enhancements.  */
  338.  
  339. /* Create a new stream connected to a pipe running the given command.  */
  340. extern FILE *popen (const char *command, const char *modes);
  341.  
  342. /* Close a stream opened by popen and return the status of its child.  */
  343. extern int pclose (FILE *stram);
  344.  
  345.  
  346. /* GNU extenstions.  */
  347.  
  348. /* Read an entire line from stream (upto newline), storing the text in
  349.    a buffer and storing the buffer address in *lineptr.  */
  350. extern __ssize_t getline (char **lineptr, size_t *n, FILE *stream);
  351.  
  352. /* Similar to getline except that the line terminator doesn't
  353.    have to be a newline.  */
  354. extern __ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);
  355.  
  356. #ifdef __cplusplus
  357.     }
  358. #endif
  359.  
  360. #endif
  361.