home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / h / stdio < prev    next >
Encoding:
Text File  |  2004-09-05  |  14.1 KB  |  460 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/stdio.h,v $
  4.  * $Date: 2004/08/08 11:32:41 $
  5.  * $Revision: 1.11 $
  6.  * $State: Exp $
  7.  * $Author: peter $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* ANSI Standard 4.9: Input/Output <stdio.h>.  */
  12.  
  13. #ifndef __STDIO_H
  14.  
  15. #if !defined __need_FILE
  16. #define __STDIO_H
  17. #endif
  18.  
  19. #include <unixlib/features.h>
  20. #include <unixlib/types.h>
  21. #define __need_size_t
  22. #define __need_NULL
  23. #include <stddef.h>
  24.  
  25. #if !defined __FILE_defined && (defined __STDIO_H || defined __need_FILE)
  26. #define __FILE_defined
  27. typedef struct __iobuf FILE;
  28. #endif
  29. #undef __need_FILE
  30.  
  31. #ifdef __STDIO_H
  32.  
  33. #define __need___va_list
  34. #include <stdarg.h>
  35.  
  36. __BEGIN_DECLS
  37.  
  38. typedef __off_t fpos_t;
  39.  
  40.  
  41. /* Maximum number of files that can be open at once.
  42.    Keep in sync with <limits.h>, _POSIX_OPEN_MAX.  */
  43. #define FOPEN_MAX    64
  44.  
  45. /* Maximum length of a filename.
  46.    Keep in sync with <limits.h>, _POSIX_NAME_MAX.  */
  47. #define FILENAME_MAX    252
  48.  
  49. /* Default buffer size.  */
  50. #define BUFSIZ        4096
  51.  
  52. /* End of file character.  */
  53. #define EOF        (-1)
  54.  
  55. /* The possibilities for the third argument to fseek.
  56.    <unistd.h> has the same definitions.  */
  57.  
  58. /* Seek from beginning of file.  */
  59. #ifndef SEEK_SET
  60. #define SEEK_SET    0
  61. #endif
  62. /* Seek from current position.  */
  63. #ifndef SEEK_CUR
  64. #define SEEK_CUR    1
  65. #endif
  66. /* Seek from end of file.  */
  67. #ifndef SEEK_END
  68. #define SEEK_END    2
  69. #endif
  70.  
  71. /* The mode of file input/output. */
  72. typedef struct
  73. {
  74.   unsigned int __read:1; /* Open for reading.  */
  75.   unsigned int __write:1; /* Open for writing.  */
  76.   unsigned int __append:1; /* Open for appending.  */
  77.   unsigned int __binary:1; /* Opened binary.  */
  78.   unsigned int __create:1; /* Create the file.  */
  79.   unsigned int __exclusive:1; /* Error if it already exists.  */
  80.   unsigned int __truncate:1; /* Truncate the file on opening.  */
  81. } __io_mode;
  82.  
  83. struct __iobuf
  84. {
  85.   unsigned int __magic;  /* Magic number for stream validation.  */
  86.   unsigned char *i_ptr;
  87.   unsigned char *i_base;
  88.   int i_cnt;
  89.   unsigned char *o_ptr;
  90.   unsigned char *o_base;
  91.   int o_cnt;
  92.   size_t __bufsize; /* size of buffer.  */
  93.   fpos_t __offset; /* current file position of underlying file descr. */
  94.   __io_mode __mode; /* file access mode */
  95.   unsigned char __pushedchar; /* character that has been pushed back */
  96.   int __pushedi_cnt; /* position of i_cnt before char was pushed back */
  97.   unsigned int __pushedback:1; /* ungetc has pushed back a character */
  98.   unsigned int __eof:1; /* end of file encountered */
  99.   unsigned int __error:1; /* error encountered */
  100.   unsigned int __iuserbuf:1; /* buffer from user (should not be freed) */
  101.   unsigned int __ouserbuf:1; /* buffer from user (should not be freed) */
  102.   unsigned int __linebuf:1; /* flush on newline */
  103.   unsigned int __ispipe:1; /* nonzero if opened by popen */
  104.   unsigned int __string_istream:1; /* nonzero if string input stream */
  105.   int fd; /* File descriptor.  */
  106.   FILE *next; /* next FILE in the linked list */
  107. };
  108.  
  109. #ifdef __UNIXLIB_INTERNALS
  110.  
  111. /* Magic number to fill __magic.  */
  112. #define _IOMAGIC 0xfe000000
  113.  
  114. #if __INTEGRITY_CHECK
  115. /* Nonzero if stream is a valid stream.  */
  116. #define __validfp(stream) (stream != NULL && stream->__magic == _IOMAGIC)
  117. #else
  118. #define __validfp(stream) (1)
  119. #endif
  120.  
  121. /* Invalidate a stream.  */
  122. extern void __invalidate (FILE *__stream) __THROW;
  123.  
  124. /* Make a new stream.  */
  125. extern FILE *__newstream (void) __THROW;
  126.  
  127. /* Initialise a new stream.  */
  128. extern FILE *__stream_init (int __fd, FILE *__stream) __THROW;
  129.  
  130. /* Dissect the given mode string into an __io_mode.  */
  131. extern __io_mode __getmode (const char *__mode) __THROW;
  132.  
  133. extern void __stdioinit (void);    /* initialise stdin,stdout & stderr */
  134. extern void __stdioexit (void);    /* close streams & delete tmpfile() */
  135.  
  136. /* Return the next character in the input buffer, keeping it in
  137.    the input buffer.  If the buffer is empty, then fill it.  */
  138. extern int __peek_char (FILE *__stream) __THROW;
  139.  
  140. #define __STDIOLIB__ static void (*__stdiolib)(void) = __stdioinit;
  141.  
  142. /* All streams are in a linked list.
  143.    This is the head of the list.  */
  144. extern FILE *__iob_head;
  145.  
  146. #endif  /* __UNIXLIB_INTERNALS */
  147.  
  148. /* fill buffer */
  149. extern int __filbuf (FILE *__stream) __THROW;
  150. /* flush buffer */
  151. extern int __flsbuf (int __c, FILE *__stream) __THROW;
  152.  
  153. /* Standard streams.  ANSI says these are macros.  */
  154. extern FILE *__stdin, *__stdout, *__stderr;
  155. #define stdin __stdin
  156. #define stdout __stdout
  157. #define stderr __stderr
  158.  
  159. #define _IOBF        0000070
  160.  
  161. /* The possibilities for the third argument to setvbuf.  */
  162.  
  163. /* No buffering.  */
  164. #define _IONBF        0000010
  165. /* Line buffering.  */
  166. #define _IOLBF        0000020
  167. /* Full buffering.  */
  168. #define _IOFBF        0000040
  169.  
  170. /* Return the EOF indicator for stream.  */
  171. extern int feof (FILE *__stream) __THROW;
  172. /* Return the error indicator for stream.  */
  173. extern int ferror (FILE *__stream) __THROW;
  174. extern int fisatty (FILE *__stream) __THROW;
  175.  
  176. extern void clearerr (FILE *__stream) __THROW;
  177.  
  178. #define feof(stream) ((stream)->__eof != 0)
  179. #define ferror(stream) ((stream)->__error != 0)
  180.  
  181. /* Print a message describing the meaning of the value of errno. */
  182. extern void perror (const char *__s) __THROW;
  183.  
  184. /* Open a file and create a new stream for it.  */
  185. extern FILE *fopen (const char *__restrict __filename,
  186.             const char *__restrict __mode) __THROW;
  187.  
  188. /* Open a file, replacing an existing stream with it.  */
  189. extern FILE *freopen (const char *__restrict __filename,
  190.               const char *__restrict __mode,
  191.                           FILE *__stream) __THROW;
  192.  
  193. /* Close stream, or all streams if stream is null.  */
  194. extern int fclose (FILE *__stream) __THROW;
  195.  
  196. /* Flush stream, or all streams if stream is null.  */
  197. extern int fflush (FILE *__stream) __THROW;
  198.  
  199. /* Read chunks of generic data from stream.  */
  200. extern size_t fread (void *__ptr, size_t __size,
  201.                           size_t __n, FILE *__stream) __THROW;
  202.  
  203. /* Write chunks of generic data to stream.  */
  204. extern size_t fwrite (const void *__ptr, size_t __size,
  205.                            size_t __n, FILE *__stream) __THROW;
  206.  
  207. /* If buf is null, make stream unbuffered.
  208.    If not null, use buffer buf of size BUFSIZ.  */
  209. extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
  210.  
  211. /* Make stream use buffering mode 'mode'.
  212.    If buf is not NULL, use n bytes of it for buffering;
  213.    else allocate an internal buffer n bytes long.  */
  214. extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
  215.             int __modes, size_t __n) __THROW;
  216.  
  217. /* Push a character back onto the input buffer of stream.  */
  218. extern int ungetc (int __c, FILE *__stream) __THROW;
  219.  
  220. /* Get stream's position.  */
  221. extern int fgetpos (FILE *__stream, fpos_t *__pos) __THROW;
  222. /* Set stream's position.  */
  223. extern int fsetpos (FILE *__stream, const fpos_t *__pos) __THROW;
  224.  
  225. /* Seek to a certain position on stream.  */
  226. extern int fseek (FILE *__stream, long int __off, int __whence) __THROW;
  227. extern int fseeko (FILE *__stream, __off_t __off, int __whence) __THROW;
  228. /* Return the current position of stream.  */
  229. extern long ftell (FILE *__stream) __THROW;
  230. extern __off_t ftello (FILE *__stream) __THROW;
  231. /* Rewind to the beginning of stream.  */
  232. extern void rewind (FILE *__stream) __THROW;
  233.  
  234. extern int getc (FILE *__stream) __THROW;
  235. extern int getchar (void) __THROW;
  236.  
  237. /* Read a character from stream.  */
  238. #define getc_unlocked(f) \
  239.     ((--((f)->i_cnt) >= 0 ? *((f)->i_ptr)++ : __filbuf(f)))
  240.  
  241. #if !__FEATURE_PTHREADS
  242. #define getc(f) getc_unlocked(f)
  243. #endif
  244.  
  245. /* Read a character from stdin.  */
  246. #define getchar() getc(stdin)
  247. #define getchar_unlocked() getc_unlocked(stdin)
  248.  
  249. /* Read a character from stream.  */
  250. extern int fgetc (FILE *__stream) __THROW;
  251.  
  252. #define putc_unlocked(c, stream) putc(c, stream)
  253.  
  254. /* Write a character to stream. */
  255. extern int putc (int __c, FILE *__stream) __THROW;
  256. extern int fputc (int __c, FILE *__stream) __THROW;
  257.  
  258. /* Write a character to stdout.  */
  259. extern int putchar (int __c) __THROW;
  260.  
  261. /* Get a newline-terminated string of finite length from stream.  */
  262. extern char *fgets (char *__s, size_t __n, FILE *__stream) __THROW;
  263. #define fgets_unlocked fgets
  264.  
  265. /* Get a newline-terminated string from stdin, removing the newline.  */
  266. extern char *gets (char *__s);
  267.  
  268. /* Write a string to stream.  */
  269. extern int fputs (const char *__restrict __s, FILE *__restrict __stream)
  270.      __THROW;
  271.  
  272. /* Write a string, followed by a newline, to stdout.  */
  273. extern int puts (const char *__s) __THROW;
  274.  
  275. /* Formatted I/O */
  276.  
  277. /* I know I said I would not do this, but ... */
  278.  
  279. /* Write formatted output to s from argument list arg.  limit is the
  280.    maximum number of characters to produce.  */
  281. extern int vsnprintf (char *__restrict __s, size_t __limit,
  282.               const char *__restrict __format,
  283.               __gnuc_va_list __arg)
  284.      __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
  285.  
  286. /* Write formatted output to s from argument list arg.  */
  287. extern int vsprintf (char *__restrict __s,
  288.              const char *__restrict __format, __gnuc_va_list __arg)
  289.      __THROW;
  290.  
  291. /* Write formatted output to stream from arg list arg.  */
  292. extern int vfprintf (FILE *__restrict __stream,
  293.              const char *__restrict __format, __gnuc_va_list __arg)
  294.      __THROW;
  295.  
  296. /* Write formatted output to stdio from arg list arg.  */
  297. extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg)
  298.      __THROW;
  299.  
  300. #ifndef __GNUC__
  301. #pragma -v1
  302. #endif
  303.  
  304. /* Write formatted output to s.  limit is the maximum number of characters
  305.    to produce.  */
  306. extern int snprintf (char *__restrict __s, size_t __limit,
  307.              const char *__restrict __format, ...)
  308.      __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
  309.  
  310. /* Write formatted output to s.  */
  311. extern int sprintf (char *__restrict __s,
  312.             const char *__restrict __format, ...) __THROW;
  313.  
  314. /* Write formatted output to stream.  */
  315. extern int fprintf (FILE *__restrict __stream,
  316.             const char *__restrict __format, ...) __THROW;
  317.  
  318. /* Write formatted output to stdout.  */
  319. extern int printf (const char *__restrict __format, ...) __THROW;
  320.  
  321. #ifndef __GNUC__
  322. #pragma -v2
  323. #endif
  324.  
  325. /* Read formatted input from s.  */
  326. extern int sscanf (const char *__restrict __s,
  327.            const char *__restrict __format, ...) __THROW;
  328.  
  329. /* Read formatted input from stream.  */
  330. extern int fscanf (FILE *__restrict __stream,
  331.            const char *__restrict __format, ...) __THROW;
  332.  
  333. /* Read formatted input from stdin.  */
  334. extern int scanf (const char *__restrict __format, ...) __THROW;
  335.  
  336. #ifndef __GNUC__
  337. #pragma -v0
  338. #endif
  339.  
  340. /* Read formatted input from stdin into argument list arg.  */
  341. extern int vscanf (const char *__restrict __format, __gnuc_va_list __ap)
  342.      __THROW __attribute__ ((__format__ (__scanf__, 1, 0)));
  343.  
  344. /* Read formatted input from stream into argument list arg.  */
  345. extern int vfscanf (FILE *__restrict __stream,
  346.             const char *__restrict __format, __gnuc_va_list __ap)
  347.      __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
  348.  
  349. /* Read formatted input from 's' into argument list arg.  */
  350. extern int vsscanf (const char *__restrict __s,
  351.             const char *__restrict __format, __gnuc_va_list __ap)
  352.      __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
  353.  
  354. /* How long an array of chars must be to be passed to tmpnam.  */
  355. #define L_tmpnam    255
  356.  
  357. /* The minimum number of unique filenames generated by tmpnam.  */
  358. #define TMP_MAX     217672836
  359.  
  360. /* Remove file filename.  */
  361. extern int remove (const char *__filename) __THROW;
  362.  
  363. /* Rename file oldname to newname.  */
  364. extern int rename(const char *__old, const char *__newname) __THROW;
  365.  
  366. /* Create a temporary file and open it read/write.  */
  367. extern FILE *tmpfile (void) __THROW;
  368. /* Generate a temporary filename.  */
  369. extern char *tmpnam (char *__s) __THROW;
  370. /* Re-entrant version of tmpnam(). 's' must not be null.  */
  371. extern char *tmpnam_r (char *__s) __THROW;
  372.  
  373. /* Return a pointer to a malloc'ed unique temporary filename, including
  374.    pathname.  */
  375. extern char *tempnam (const char *__dir, const char *__prefix)
  376.      __THROW __attribute_malloc__;
  377.  
  378. /* Generate a unique temporary file name for temp.  */
  379. extern char *mktemp(char *__temp) __THROW;
  380.  
  381. /* As for mktemp but returns an open file descriptor on the file.  */
  382. extern int mkstemp(char *__temp) __THROW;
  383.  
  384. /* System V enhancements.  */
  385.  
  386. /* Get a word (int) from stream.  */
  387. extern int getw (FILE *__stream) __THROW;
  388. /* Write a word (int) to stream.  */
  389. extern int putw (int __w, FILE *__stream) __THROW;
  390.  
  391. /* Default path prefix for tempnam and tmpnam.  */
  392. #define P_tmpdir "/tmp"
  393.  
  394.  
  395. /* BSD enhancements.  */
  396.  
  397. /* If BUF is NULL, make STREAM unbuffered.
  398.    Else make it use SIZE bytes of BUF for buffering.  */
  399. extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
  400.                size_t __size) __THROW;
  401.  
  402. /* Make STREAM line-buffered.  */
  403. extern void setlinebuf (FILE *__stream) __THROW;
  404.  
  405. extern int sys_nerr;
  406. /* This is also defined in <errno.h> */
  407. extern const char *sys_errlist[];
  408.  
  409. /* POSIX enhancements.  */
  410.  
  411. /* Create a new stream that refers to an existing system file descriptor.  */
  412. extern FILE *fdopen (int __fd, const char *__modes) __THROW;
  413.  
  414. /* Return the system file descriptor for stream.  */
  415. extern int fileno (FILE *__stream) __THROW;
  416. #define fileno(f)    ((f)->fd)
  417.  
  418. #define L_ctermid 16
  419.  
  420. /* Return the name of the controlling terminal.  */
  421. extern char *ctermid (char *__s) __THROW;
  422.  
  423. /* Return the name of the current user.  */
  424. extern char *cuserid (char *__s) __THROW;
  425.  
  426. /* POSIX 2 enhancements.  */
  427.  
  428. /* Create a new stream connected to a pipe running the given command.  */
  429. extern FILE *popen (const char *__command, const char *__modes) __THROW;
  430.  
  431. /* Close a stream opened by popen and return the status of its child.  */
  432. extern int pclose (FILE *__stream) __THROW;
  433.  
  434.  
  435. /* GNU extenstions.  */
  436.  
  437. #ifdef __USE_GNU
  438. /* Read an entire line from stream (upto newline), storing the text in
  439.    a buffer and storing the buffer address in *lineptr.  */
  440. extern __ssize_t getline (char **__restrict __lineptr,
  441.               size_t *__restrict __n,
  442.               FILE *__restrict __stream) __THROW;
  443.  
  444. /* Similar to getline except that the line terminator doesn't
  445.    have to be a newline.  */
  446. extern __ssize_t getdelim (char **__restrict __lineptr,
  447.                size_t *__restrict __n,
  448.                        int __delimiter,
  449.                FILE *__restrict __stream) __THROW;
  450. #endif
  451.  
  452. #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
  453. #include <getopt.h>
  454. #endif
  455.  
  456. __END_DECLS
  457.  
  458. #endif /* __STDIO_H */
  459. #endif /* ! __STDIO_H */
  460.