home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / h / stdio < prev    next >
Encoding:
Text File  |  2006-09-17  |  17.5 KB  |  588 lines

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