home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / include / libscl / h / stdio < prev    next >
Encoding:
Text File  |  2004-09-05  |  13.8 KB  |  420 lines

  1. /* stdio.h
  2.  
  3.    For use with the GNU compilers and the SharedCLibrary.
  4.    Copyright (c) 1997, 1998, 1999, 2003, 2004 Nick Burrett.
  5.  
  6.    To use filename translation, define __UNAME.  */
  7.  
  8. #ifndef __STDIO_H
  9. #define __STDIO_H
  10.  
  11. #ifndef __STDDEF_H
  12. #include <stddef.h>
  13. #endif
  14.  
  15. #define __need__va_list
  16. #include <stdarg.h>
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #define __LIB_VERSION 300
  23.  
  24. typedef struct __fpos_t_struct
  25. {
  26.   unsigned long __lo;
  27. } fpos_t;
  28.   
  29. typedef struct __FILE_struct
  30. {
  31.   unsigned char *__ptr;
  32.   int __icnt;
  33.   int __ocnt;
  34.   int __flag;
  35.   unsigned char *__base;
  36.   void *__file;
  37.   long __pos;
  38.   int __bufsiz;
  39.   int __signature;
  40.   int *internal;
  41. } FILE;
  42.  
  43. #define _IOEOF 0x40
  44. #define _IOERR 0x80
  45. /* Full buffering.  */
  46. #define _IOFBF 0x100
  47. /* Line buffering.  */
  48. #define _IOLBF 0x200
  49. /* No buffering.  */
  50. #define _IONBF 0x400
  51. /* Default buffer size.  */
  52. #define BUFSIZ (4096)
  53. /* End of file character.  */
  54. #define EOF (-1)
  55.  
  56. /* Maximum number of files that can be open at once.  */
  57. #define FOPEN_MAX 8
  58. /* Number of open files that is imposed by this library.  */
  59. #define _SYS_OPEN 16
  60.  
  61. /* Maximum length of a filename.  */
  62. #define FILENAME_MAX 80
  63.  
  64.  
  65. /* Seek from beginning of file.  */
  66. #ifndef SEEK_SET
  67. #define SEEK_SET 0
  68. #endif
  69. /* Seek from current position.  */
  70. #ifndef SEEK_CUR
  71. #define SEEK_CUR 1
  72. #endif
  73. /* Seek from end of file.  */
  74. #ifndef SEEK_END
  75. #define SEEK_END 2
  76. #endif
  77.  
  78. /* How long an array of chars must be to be passed to tmpnam.  */
  79. #define L_tmpnam 20
  80. /* The maximum number of unique filenames generated by tmpnam.  */
  81. #define TMP_MAX 1000000000
  82.  
  83. /* Standard streams.  */
  84. extern FILE __iob[];
  85.  
  86. #define stdin (&__iob[0])
  87. #define stdout (&__iob[1])
  88. #define stderr (&__iob[2])
  89.  
  90. /* Delete file 'filename'.  */
  91. extern int remove (const char *__filename);
  92.  
  93. #ifdef __UNAME
  94. #define remove(f) (remove(__uname(f)))
  95. #endif
  96.  
  97. /* Rename a file called 'oldname' to 'newname'. If rename fails
  98.    it returns -1.  */
  99. extern int rename (const char *__oldname, const char *__newname);
  100.  
  101. #ifdef __UNAME
  102. #define rename(f, g) (rename(__uname(f), __uname(g)))
  103. #endif
  104.  
  105. /* Create a temporary binary file for updade mode, as if calling
  106.    fopen with mode "wb+".  The file is deleted automatically when
  107.    it is closed or when the program terminates.  */
  108. extern FILE *tmpfile (void);
  109.  
  110. /* Construct and return a file name that is a valid and does not
  111.    name any existing file. If 'result' is null, the return value
  112.    points to an internal static string. Otherwise, 'result' points
  113.    to an array of at least L_tmpnam chars.  */
  114. extern char *tmpnam (char *__result);
  115.  
  116. /* Cause 'stream' to be closed and the connection to the corresponding
  117.    file to be broken.  All buffered output is written and buffered
  118.    input is discarded. Returns 0 on success, EOF if an error was detected.  */
  119. extern int fclose (FILE *__stream);
  120.  
  121. /* Cause any buffered output on 'stream' to be delivered to the file.
  122.    If 'stream' is null, then fflush causes buffered output on all open
  123.    output streams. Returns EOF if a write error occurs, zero otherwise.  */
  124. extern int fflush (FILE *__stream);
  125.  
  126. /* Open a stream for I/O to the file 'filename' and return a pointer
  127.    to the stream.  */
  128. extern FILE *fopen (const char *__filename, const char *__opentype);
  129.  
  130. #ifdef __UNAME
  131. #define fopen(f, t) (fopen(__uname(f), t))
  132. #endif
  133.  
  134. /* Close the stream 'stream', ignoring any errors. Then 'filename'
  135.    is opened with 'opentype' with the same stream object 'stream'.
  136.    Returns null on failure.  Usually used to connect to standard
  137.    streams e.g. stdin, stdout or stderr.  */
  138. extern FILE *freopen (const char *__filename, const char *__opentype,
  139.               FILE *__stream);
  140.  
  141. #ifdef __UNAME
  142. #define freopen(f, t, s) (freopen(__uname(f), t, s))
  143. #endif
  144.  
  145.  
  146. /* Set file buffering for 'stream'. If 'buf' is null, then
  147.    file buffering is turned off, otherwise we use full file buffering.  */
  148. extern void setbuf (FILE *__stream, char *__buf);
  149.  
  150. /* Specify that the stream 'stream' should have the buffering mode
  151.    'mode', which can be either _IOFBF (full buffering), _IOLBF (line
  152.    buffering) or _IONBF (unbuffered input/output).
  153.  
  154.    If 'buf' is null, then setvbuf allocates a buffer itself using
  155.    malloc. This is freed when the stream is closed.
  156.  
  157.    Otherwise 'buf' is a character array of 'size' characters.  */
  158. extern int setvbuf (FILE *__stream, char *__buf, int __mode,
  159.             size_t __size);
  160.  
  161. /* Print the optional arguments under control of the template
  162.    string 'fmt' to the stream stdout. Returns the number of characters
  163.    printed, or a negative value if there was an output error.  */
  164. extern int printf (const char *__fmt, ...);
  165.  
  166. /* Similar to printf except the output is written to the stream
  167.    'stream' instead of stdout.  */
  168. extern int fprintf (FILE *__stream, const char *__fmt, ...);
  169.  
  170. /* Similar to printf except the output is stored in the array
  171.    'string'. A null terminating character is also written.  */
  172. extern int sprintf (char *__string, const char *__fmt, ...);
  173.  
  174. /* Read formatted input from the stream stdin under control
  175.    of the template 'fmt'. Returns the number of successful
  176.    assignments.  */
  177. extern int scanf (const char *__fmt, ...);
  178.  
  179. /* Similar to scanf but reads from the stream 'stream'.  */
  180. extern int fscanf (FILE *__stream, const char *__fmt, ...);
  181.  
  182. /* Similar to scanf but reads from the array 'string'.  */
  183. extern int sscanf (const char *__string, const char *__fmt, ...);
  184.  
  185. /* Write formatted output to s from argument list arg.  limit is the
  186.    maximum number of characters to produce.  */
  187. extern int vsnprintf (char *__restrict __s, size_t __limit,
  188.                       const char *__restrict __format,
  189.                       __gnuc_va_list __arg)
  190.      __attribute__ ((__format__ (__printf__, 3, 0)));
  191.  
  192. /* Write formatted output to s from argument list arg.  */
  193. extern int vsprintf (char *__restrict __s,
  194.                      const char *__restrict __format, __gnuc_va_list __arg);
  195.  
  196. /* Write formatted output to stream from arg list arg.  */
  197. extern int vfprintf (FILE *__restrict __stream,
  198.                      const char *__restrict __format, __gnuc_va_list __arg);
  199.  
  200. /* Write formatted output to stdio from arg list arg.  */
  201. extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
  202.  
  203. #ifdef __GNUC__
  204. extern int __gcc_vsnprintf (char *__restrict __s, size_t __limit,
  205.                 const char *__restrict __format,
  206.                 __gnuc_va_list *__arg)
  207.      __attribute__ ((__format__ (__printf__, 3, 0)));
  208.      extern int __gcc_vsprintf (char *__restrict __s,
  209.                 const char *__restrict __format, __gnuc_va_list *__arg);
  210. extern int __gcc_vfprintf (FILE *__restrict __stream,
  211.                      const char *__restrict __format, __gnuc_va_list *__arg);
  212. extern int __gcc_vprintf (const char *__restrict __format, __gnuc_va_list *__arg);
  213.  
  214. #define vsnprintf(__s,__limit,__fmt,__ap) \
  215.     (__gcc_vsnprintf(__s,__limit,__fmt, &__ap))
  216. #define vsprintf(__s,__fmt,__ap) (__gcc_vsprintf(__s, __fmt, &__ap))
  217. #define vfprintf(__s,__fmt,__ap) (__gcc_vfprintf(__s, __fmt, &__ap))
  218. #define vprintf(__fmt,__ap) (__gcc_vprintf(__fmt, &__ap))
  219. #endif
  220.  
  221. #ifndef __GNUC__
  222. #pragma -v1
  223. #endif
  224.  
  225. /* Write formatted output to s.  limit is the maximum number of characters
  226.    to produce.  */
  227. extern int snprintf (char *__restrict __s, size_t __limit,
  228.                      const char *__restrict __format, ...)
  229.      __attribute__ ((__format__ (__printf__, 3, 4)));
  230.      
  231.      /* Write formatted output to s.  */
  232.      extern int sprintf (char *__restrict __s,
  233.                     const char *__restrict __format, ...);
  234.  
  235. /* Write formatted output to stream.  */
  236. extern int fprintf (FILE *__restrict __stream,
  237.                     const char *__restrict __format, ...);
  238.  
  239. /* Write formatted output to stdout.  */
  240. extern int printf (const char *__restrict __format, ...);
  241.  
  242. #ifndef __GNUC__
  243. #pragma -v2
  244. #endif
  245.  
  246. /* Read formatted input from s.  */
  247. extern int sscanf (const char *__restrict __s,
  248.                    const char *__restrict __format, ...);
  249.  
  250. /* Read formatted input from stream.  */
  251. extern int fscanf (FILE *__restrict __stream,
  252.                    const char *__restrict __format, ...);
  253.  
  254. /* Read formatted input from stdin.  */
  255. extern int scanf (const char *__restrict __format, ...);
  256.  
  257. #ifndef __GNUC__
  258. #pragma -v0
  259. #endif
  260.  
  261. /* Read formatted input from stdin into argument list arg.  */
  262. extern int vscanf (const char *__restrict __format, __gnuc_va_list __ap)
  263.      __attribute__ ((__format__ (__scanf__, 1, 0)));
  264.  
  265. /* Read formatted input from stream into argument list arg.  */
  266. extern int vfscanf (FILE *__restrict __stream,
  267.                     const char *__restrict __format, __gnuc_va_list __ap)
  268.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  269.  
  270. /* Read formatted input from 's' into argument list arg.  */
  271. extern int vsscanf (const char *__restrict __s,
  272.                     const char *__restrict __format, __gnuc_va_list __ap)
  273.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  274.      
  275. #ifdef __GNUC__
  276. extern int __gcc_vscanf (const char *__restrict __format, __gnuc_va_list *__ap)
  277.      __attribute__ ((__format__ (__scanf__, 1, 0)));
  278. extern int __gcc_vfscanf (FILE *__restrict __stream,
  279.               const char *__restrict __format, __gnuc_va_list *__ap)
  280.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  281. extern int __gcc_vsscanf (const char *__restrict __s,
  282.                     const char *__restrict __format, __gnuc_va_list *__ap)
  283.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  284.  
  285. #define vscanf(__fmt,__ap) (__gcc_vscanf(__fmt, &__ap))
  286. #define vfscanf(__s,__fmt,__ap) (__gcc_vfscanf(__s, __fmt, &__ap))
  287. #define vsscanf(__s,__fmt,__ap) (__gcc_vsscanf(__s, __fmt, &__ap))
  288. #endif
  289.  
  290.  
  291.  
  292. /* Read the next character as an unsigned char from the stream
  293.    'stream' and return its value, converted to an int.  EOF
  294.    is returned on read error/end-of-file.  */
  295. extern int fgetc (FILE *__stream);
  296. extern int __filbuf (FILE *__stream);
  297.  
  298. /* Similar to fgetc but implemented as a macro, so stream can be
  299.    evaluated more than once.  */
  300. extern int getc (FILE *__stream);
  301. #define getc(p) \
  302.  (--((p)->__icnt) >= 0 ? *((p)->__ptr)++ : __filbuf(p))
  303.  
  304. /* Equivalent to getc with a stream of stdin.  */
  305. extern int getchar (void);
  306. #define getchar() getc(stdin)
  307.  
  308. /* Read chars from the stream 'stream' up to and including a
  309.    newline character and stores them in the string 's'. A null
  310.    character is added to mark the end of the string.  The number
  311.    of characters to read at most is 'count - 1'.  */
  312. extern char *fgets (char *__s, int __count, FILE *__stream);
  313.  
  314. /* Read chars from the stream 'stdin' up to and including a
  315.    new line. The newline character is discarded.  */
  316. extern char *gets(char *__s);
  317. extern int __flsbuf(int __c, FILE *__stream);
  318.  
  319. /* Convert the character 'c' to type unsigned char and writes it
  320.    to stream 'stream'.  EOF is returned if an error occurs;
  321.    otherwise the character 'c' is returned.  */
  322. extern int putc (int __c, FILE *__stream);
  323.  
  324. #define putc(ch, p) \
  325.  (--((p)->__ocnt) >= 0 ? (*((p)->__ptr)++ = (ch)) : __flsbuf(ch,p))
  326.  
  327. extern int fputc (int __c, FILE *__stream);
  328.  
  329. /* Equivalent to putc with stdout as the value of the stream argument.  */
  330. extern int putchar (int __ch);
  331. #define putchar(ch) putc(ch, stdout)
  332.  
  333.  
  334. /* Write the string 's' top the stream 'stream'. The terminating null
  335.    character is not written, and a newline character is not added, either.  */
  336. extern int fputs(const char *__s, FILE *__stream);
  337.  
  338. /* Write the string 's' to stdout.  */
  339. extern int puts (const char *__s);
  340.  
  341. /* Pushes back the character 'c' onto the input stream 'stream'.
  342.    The next input from 'stream' will read 'c' before anything else.
  343.    If 'c' is EOF, ungetc does nothing and just returns EOF.  */
  344. extern int ungetc (int __c, FILE *__stream);
  345.  
  346. /* Read up to 'count' objects of size 'size' into the array 'data',
  347.    from the stream 'stream'. Return the number of objects actually
  348.    read.  */
  349. extern size_t fread (void *__data, size_t __size, size_t __count,
  350.              FILE *stream);
  351.  
  352. /* Write up to 'count' objects of size 'size' from the array 'data',
  353.    to the stream 'stream'. The return value is normally 'count' if the
  354.    call succeeds.  */
  355. extern size_t fwrite (const void *__data, size_t __size, size_t __count,
  356.               FILE *__stream);
  357.  
  358. /* Store the value of the file position indicator for the
  359.    stream 'stream' in the fpos_t object pointed to by 'position'.
  360.    fgetpos returns zero on success.  */
  361. extern int fgetpos (FILE *__stream, fpos_t *__position);
  362.  
  363. /* Change the file position of the stream 'stream'. 'whence'
  364.    must be one of the constants SEEK_SET, SEEK_CUR, SEEK_END,
  365.    to indicate the meaning of the relative 'offset'.  */
  366. extern int fseek (FILE *__stream, long int __offset, int __whence);
  367.  
  368. /* Set the file position indicator for the stream 'stream' to the
  369.    position 'position', which must be set by a previous call to
  370.    fgetpos.  */
  371. extern int fsetpos (FILE *__stream, const fpos_t *__position);
  372.  
  373. /* Return the current file position of the stream 'stream'.
  374.    If a failure occurs, -1 is returned.  */
  375. extern long int ftell (FILE *__stream);
  376.  
  377. /* Positions the stream 'stream' at the beginning of the file.
  378.    Equivalent to fseek (stream, 0, SEEK_SET).  */
  379. extern void rewind (FILE *__stream);
  380.  
  381. /* Clears the end-of-file and error indicators for the stream
  382.    'stream'.  */
  383. extern void clearerr (FILE *__stream);
  384.  
  385. /* Return nonzero if the end-of-file indicator for stream 'stream'
  386.    is set.  */
  387. extern int feof (FILE *__stream);
  388. #define feof(stream) ((stream)->__flag & _IOEOF)
  389.  
  390. /* Return nonzero if the error indicator for the stream 'stream'
  391.    is set.  */
  392. extern int ferror (FILE *__stream);
  393. #define ferror(stream) ((stream)->__flag & _IOERR)
  394.  
  395. /* Print an error message to the stream 'stderr'.
  396.  
  397.    If 'message' is null, the error message corresponding to
  398.    'errno' is printed.  */
  399. extern void perror (const char *__message);
  400.  
  401. /* Extensions to the SharedCLibrary.  */
  402.  
  403. #ifdef __UNAME
  404. extern char *__uname (char *name);
  405. #endif
  406.  
  407. /* Return the system file descriptor for stream.  */
  408. extern int fileno (FILE *__stream);
  409. #define fileno(f) ((int)(f))
  410.  
  411. /* Create a new stream that refers to an existing system file descriptor.  */
  412. extern FILE *fdopen (int __fd, const char *__modes);
  413.  
  414.  
  415. #ifdef __cplusplus
  416. }
  417. #endif
  418.  
  419. #endif
  420.