home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / libscl / h / stdio < prev    next >
Encoding:
Text File  |  2006-09-17  |  16.6 KB  |  474 lines

  1. /* stdio.h standard header for the RISC OS SharedCLibrary.
  2.    Copyright (c) 1997-2005 Nick Burrett
  3.    Copyright (c) 2006 UnixLib Developers
  4.    All rights reserved.
  5.  
  6.    Redistribution and use in source and binary forms, with or without
  7.    modification, are permitted provided that the following conditions
  8.    are met:
  9.    1. Redistributions of source code must retain the above copyright
  10.       notice, this list of conditions and the following disclaimer.
  11.    2. Redistributions in binary form must reproduce the above copyright
  12.       notice, this list of conditions and the following disclaimer in the
  13.       documentation and/or other materials provided with the distribution.
  14.    3. The name of the author may not be used to endorse or promote products
  15.       derived from this software without specific prior written permission.
  16.  
  17.    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  27.  
  28.  
  29. /* To use filename translation, define __RISCOSIFY.  */
  30.  
  31. #ifndef __STDIO_H
  32. #define __STDIO_H
  33.  
  34. #ifndef __STDDEF_H
  35. #include <stddef.h>
  36. #endif
  37.  
  38. #define __need__va_list
  39. #include <stdarg.h>
  40. /* Castle C/C++ compatibility */
  41. #define __va_list va_list
  42.  
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46.  
  47. #define __LIB_VERSION 300
  48.  
  49. typedef struct __fpos_t_struct
  50. {
  51.   unsigned long __lo;
  52. } fpos_t;
  53.   
  54. typedef struct __FILE_struct
  55. {
  56.   unsigned char *__ptr;
  57.   int __icnt;
  58.   int __ocnt;
  59.   int __flag;
  60.   unsigned char *__base;
  61.   void *__file;
  62.   long __pos;
  63.   int __bufsiz;
  64.   int __signature;
  65.   int *internal;
  66. } FILE;
  67.  
  68. #define _IOEOF 0x40
  69. #define _IOERR 0x80
  70. /* Full buffering.  */
  71. #define _IOFBF 0x100
  72. /* Line buffering.  */
  73. #define _IOLBF 0x200
  74. /* No buffering.  */
  75. #define _IONBF 0x400
  76. /* Default buffer size.  */
  77. #define BUFSIZ (4096)
  78. /* End of file character.  */
  79. #define EOF (-1)
  80.  
  81. /* Maximum number of files that can be open at once.  */
  82. #define FOPEN_MAX 8
  83. /* Number of open files that is imposed by this library.  */
  84. #define _SYS_OPEN 16
  85.  
  86. /* Maximum length of a filename.  */
  87. #define FILENAME_MAX 80
  88.  
  89.  
  90. /* Seek from beginning of file.  */
  91. #ifndef SEEK_SET
  92. #define SEEK_SET 0
  93. #endif
  94. /* Seek from current position.  */
  95. #ifndef SEEK_CUR
  96. #define SEEK_CUR 1
  97. #endif
  98. /* Seek from end of file.  */
  99. #ifndef SEEK_END
  100. #define SEEK_END 2
  101. #endif
  102.  
  103. /* How long an array of chars must be to be passed to tmpnam.  */
  104. #define L_tmpnam 20
  105. /* The maximum number of unique filenames generated by tmpnam.  */
  106. #define TMP_MAX 1000000000
  107.  
  108. /* Standard streams.  */
  109. extern FILE __iob[];
  110.  
  111. #define stdin (&__iob[0])
  112. #define stdout (&__iob[1])
  113. #define stderr (&__iob[2])
  114.  
  115. /* Delete file 'filename'.  */
  116. extern int remove (const char *__filename);
  117.  
  118. #ifdef __RISCOSIFY
  119. #define remove(f) (remove(__riscosify_scl(f, 0)))
  120. #endif
  121.  
  122. /* Rename a file called 'oldname' to 'newname'. If rename fails
  123.    it returns -1.  */
  124. extern int rename (const char *__oldname, const char *__newname);
  125.  
  126. #ifdef __RISCOSIFY
  127. #define rename(f, g) (rename(__riscosify_scl(f, 0), __riscosify_scl(g, 1)))
  128. #endif
  129.  
  130. /* Create a temporary binary file for updade mode, as if calling
  131.    fopen with mode "wb+".  The file is deleted automatically when
  132.    it is closed or when the program terminates.  */
  133. extern FILE *tmpfile (void);
  134.  
  135. /* Construct and return a file name that is a valid and does not
  136.    name any existing file. If 'result' is null, the return value
  137.    points to an internal static string. Otherwise, 'result' points
  138.    to an array of at least L_tmpnam chars.  */
  139. extern char *tmpnam (char *__result);
  140.  
  141. /* Cause 'stream' to be closed and the connection to the corresponding
  142.    file to be broken.  All buffered output is written and buffered
  143.    input is discarded. Returns 0 on success, EOF if an error was detected.  */
  144. extern int fclose (FILE *__stream);
  145.  
  146. /* Cause any buffered output on 'stream' to be delivered to the file.
  147.    If 'stream' is null, then fflush causes buffered output on all open
  148.    output streams. Returns EOF if a write error occurs, zero otherwise.  */
  149. extern int fflush (FILE *__stream);
  150.  
  151. /* Open a stream for I/O to the file 'filename' and return a pointer
  152.    to the stream.  */
  153. extern FILE *fopen (const char *__filename, const char *__opentype);
  154.  
  155. #ifdef __RISCOSIFY
  156. #define fopen(f, t) (fopen(__riscosify_scl(f, (t)[0] == 'a' || (t)[0] == 'w'), t))
  157. #endif
  158.  
  159. /* Close the stream 'stream', ignoring any errors. Then 'filename'
  160.    is opened with 'opentype' with the same stream object 'stream'.
  161.    Returns null on failure.  Usually used to connect to standard
  162.    streams e.g. stdin, stdout or stderr.  */
  163. extern FILE *freopen (const char *__filename, const char *__opentype,
  164.               FILE *__stream);
  165.  
  166. #ifdef __RISCOSIFY
  167. #define freopen(f, t, s) (freopen(__riscosify_scl(f, (t)[0] == 'a' || (t)[0] == 'w'), t, s))
  168. #endif
  169.  
  170.  
  171. /* Set file buffering for 'stream'. If 'buf' is null, then
  172.    file buffering is turned off, otherwise we use full file buffering.  */
  173. extern void setbuf (FILE *__stream, char *__buf);
  174.  
  175. /* Specify that the stream 'stream' should have the buffering mode
  176.    'mode', which can be either _IOFBF (full buffering), _IOLBF (line
  177.    buffering) or _IONBF (unbuffered input/output).
  178.  
  179.    If 'buf' is null, then setvbuf allocates a buffer itself using
  180.    malloc. This is freed when the stream is closed.
  181.  
  182.    Otherwise 'buf' is a character array of 'size' characters.  */
  183. extern int setvbuf (FILE *__stream, char *__buf, int __mode,
  184.             size_t __size);
  185.  
  186. /* Print the optional arguments under control of the template
  187.    string 'fmt' to the stream stdout. Returns the number of characters
  188.    printed, or a negative value if there was an output error.  */
  189. extern int printf (const char *__fmt, ...);
  190.  
  191. /* Similar to printf except the output is written to the stream
  192.    'stream' instead of stdout.  */
  193. extern int fprintf (FILE *__stream, const char *__fmt, ...);
  194.  
  195. /* Similar to printf except the output is stored in the array
  196.    'string'. A null terminating character is also written.  */
  197. extern int sprintf (char *__string, const char *__fmt, ...);
  198.  
  199. /* Read formatted input from the stream stdin under control
  200.    of the template 'fmt'. Returns the number of successful
  201.    assignments.  */
  202. extern int scanf (const char *__fmt, ...);
  203.  
  204. /* Similar to scanf but reads from the stream 'stream'.  */
  205. extern int fscanf (FILE *__stream, const char *__fmt, ...);
  206.  
  207. /* Similar to scanf but reads from the array 'string'.  */
  208. extern int sscanf (const char *__string, const char *__fmt, ...);
  209.  
  210. /* Write formatted output to s from argument list arg.  limit is the
  211.    maximum number of characters to produce.  */
  212. extern int vsnprintf (char *__restrict __s, size_t __limit,
  213.                       const char *__restrict __format,
  214.                       __gnuc_va_list __arg)
  215.      __attribute__ ((__format__ (__printf__, 3, 0)));
  216.  
  217. /* Write formatted output to s from argument list arg.  */
  218. extern int vsprintf (char *__restrict __s,
  219.                      const char *__restrict __format, __gnuc_va_list __arg);
  220.  
  221. /* Write formatted output to stream from arg list arg.  */
  222. extern int vfprintf (FILE *__restrict __stream,
  223.                      const char *__restrict __format, __gnuc_va_list __arg);
  224.  
  225. /* Write formatted output to stdio from arg list arg.  */
  226. extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
  227.  
  228. #ifdef __GNUC__
  229. extern int __gcc_vsnprintf (char *__restrict __s, size_t __limit,
  230.                 const char *__restrict __format,
  231.                 __gnuc_va_list *__arg)
  232.      __attribute__ ((__format__ (__printf__, 3, 0)));
  233.      extern int __gcc_vsprintf (char *__restrict __s,
  234.                 const char *__restrict __format, __gnuc_va_list *__arg);
  235. extern int __gcc_vfprintf (FILE *__restrict __stream,
  236.                      const char *__restrict __format, __gnuc_va_list *__arg);
  237. extern int __gcc_vprintf (const char *__restrict __format, __gnuc_va_list *__arg);
  238.  
  239. #define vsnprintf(__s,__limit,__fmt,__ap) \
  240.     (__gcc_vsnprintf(__s,__limit,__fmt, &__ap))
  241. #define vsprintf(__s,__fmt,__ap) (__gcc_vsprintf(__s, __fmt, &__ap))
  242. #define vfprintf(__s,__fmt,__ap) (__gcc_vfprintf(__s, __fmt, &__ap))
  243. #define vprintf(__fmt,__ap) (__gcc_vprintf(__fmt, &__ap))
  244. #endif
  245.  
  246. #ifndef __GNUC__
  247. #pragma -v1
  248. #endif
  249.  
  250. /* Write formatted output to s.  limit is the maximum number of characters
  251.    to produce.  */
  252. extern int snprintf (char *__restrict __s, size_t __limit,
  253.                      const char *__restrict __format, ...)
  254.      __attribute__ ((__format__ (__printf__, 3, 4)));
  255.      
  256.      /* Write formatted output to s.  */
  257.      extern int sprintf (char *__restrict __s,
  258.                     const char *__restrict __format, ...);
  259.  
  260. /* Write formatted output to stream.  */
  261. extern int fprintf (FILE *__restrict __stream,
  262.                     const char *__restrict __format, ...);
  263.  
  264. /* Write formatted output to stdout.  */
  265. extern int printf (const char *__restrict __format, ...);
  266.  
  267. #ifndef __GNUC__
  268. #pragma -v2
  269. #endif
  270.  
  271. /* Read formatted input from s.  */
  272. extern int sscanf (const char *__restrict __s,
  273.                    const char *__restrict __format, ...);
  274.  
  275. /* Read formatted input from stream.  */
  276. extern int fscanf (FILE *__restrict __stream,
  277.                    const char *__restrict __format, ...);
  278.  
  279. /* Read formatted input from stdin.  */
  280. extern int scanf (const char *__restrict __format, ...);
  281.  
  282. #ifndef __GNUC__
  283. #pragma -v0
  284. #endif
  285.  
  286. /* Read formatted input from stdin into argument list arg.  */
  287. extern int vscanf (const char *__restrict __format, __gnuc_va_list __ap)
  288.      __attribute__ ((__format__ (__scanf__, 1, 0)));
  289.  
  290. /* Read formatted input from stream into argument list arg.  */
  291. extern int vfscanf (FILE *__restrict __stream,
  292.                     const char *__restrict __format, __gnuc_va_list __ap)
  293.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  294.  
  295. /* Read formatted input from 's' into argument list arg.  */
  296. extern int vsscanf (const char *__restrict __s,
  297.                     const char *__restrict __format, __gnuc_va_list __ap)
  298.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  299.      
  300. #ifdef __GNUC__
  301. extern int __gcc_vscanf (const char *__restrict __format, __gnuc_va_list *__ap)
  302.      __attribute__ ((__format__ (__scanf__, 1, 0)));
  303. extern int __gcc_vfscanf (FILE *__restrict __stream,
  304.               const char *__restrict __format, __gnuc_va_list *__ap)
  305.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  306. extern int __gcc_vsscanf (const char *__restrict __s,
  307.                     const char *__restrict __format, __gnuc_va_list *__ap)
  308.      __attribute__ ((__format__ (__scanf__, 2, 0)));
  309.  
  310. #define vscanf(__fmt,__ap) (__gcc_vscanf(__fmt, &__ap))
  311. #define vfscanf(__s,__fmt,__ap) (__gcc_vfscanf(__s, __fmt, &__ap))
  312. #define vsscanf(__s,__fmt,__ap) (__gcc_vsscanf(__s, __fmt, &__ap))
  313. #endif
  314.  
  315.  
  316.  
  317. /* Read the next character as an unsigned char from the stream
  318.    'stream' and return its value, converted to an int.  EOF
  319.    is returned on read error/end-of-file.  */
  320. extern int fgetc (FILE *__stream);
  321. extern int __filbuf (FILE *__stream);
  322.  
  323. /* Similar to fgetc but implemented as a macro, so stream can be
  324.    evaluated more than once.  */
  325. extern int getc (FILE *__stream);
  326. #define getc(p) \
  327.  (--((p)->__icnt) >= 0 ? *((p)->__ptr)++ : __filbuf(p))
  328.  
  329. /* Equivalent to getc with a stream of stdin.  */
  330. extern int getchar (void);
  331. #define getchar() getc(stdin)
  332.  
  333. /* Read chars from the stream 'stream' up to and including a
  334.    newline character and stores them in the string 's'. A null
  335.    character is added to mark the end of the string.  The number
  336.    of characters to read at most is 'count - 1'.  */
  337. extern char *fgets (char *__s, int __count, FILE *__stream);
  338.  
  339. /* Read chars from the stream 'stdin' up to and including a
  340.    new line. The newline character is discarded.  */
  341. extern char *gets(char *__s);
  342. extern int __flsbuf(int __c, FILE *__stream);
  343.  
  344. /* Convert the character 'c' to type unsigned char and writes it
  345.    to stream 'stream'.  EOF is returned if an error occurs;
  346.    otherwise the character 'c' is returned.  */
  347. extern int putc (int __c, FILE *__stream);
  348.  
  349. #define putc(ch, p) \
  350.  (--((p)->__ocnt) >= 0 ? (*((p)->__ptr)++ = (ch)) : __flsbuf(ch,p))
  351.  
  352. extern int fputc (int __c, FILE *__stream);
  353.  
  354. /* Equivalent to putc with stdout as the value of the stream argument.  */
  355. extern int putchar (int __ch);
  356. #define putchar(ch) putc(ch, stdout)
  357.  
  358.  
  359. /* Write the string 's' top the stream 'stream'. The terminating null
  360.    character is not written, and a newline character is not added, either.  */
  361. extern int fputs(const char *__s, FILE *__stream);
  362.  
  363. /* Write the string 's' to stdout.  */
  364. extern int puts (const char *__s);
  365.  
  366. /* Pushes back the character 'c' onto the input stream 'stream'.
  367.    The next input from 'stream' will read 'c' before anything else.
  368.    If 'c' is EOF, ungetc does nothing and just returns EOF.  */
  369. extern int ungetc (int __c, FILE *__stream);
  370.  
  371. /* Read up to 'count' objects of size 'size' into the array 'data',
  372.    from the stream 'stream'. Return the number of objects actually
  373.    read.  */
  374. extern size_t fread (void *__data, size_t __size, size_t __count,
  375.              FILE *stream);
  376.  
  377. /* Write up to 'count' objects of size 'size' from the array 'data',
  378.    to the stream 'stream'. The return value is normally 'count' if the
  379.    call succeeds.  */
  380. extern size_t fwrite (const void *__data, size_t __size, size_t __count,
  381.               FILE *__stream);
  382.  
  383. /* Store the value of the file position indicator for the
  384.    stream 'stream' in the fpos_t object pointed to by 'position'.
  385.    fgetpos returns zero on success.  */
  386. extern int fgetpos (FILE *__stream, fpos_t *__position);
  387.  
  388. /* Change the file position of the stream 'stream'. 'whence'
  389.    must be one of the constants SEEK_SET, SEEK_CUR, SEEK_END,
  390.    to indicate the meaning of the relative 'offset'.  */
  391. extern int fseek (FILE *__stream, long int __offset, int __whence);
  392.  
  393. /* Set the file position indicator for the stream 'stream' to the
  394.    position 'position', which must be set by a previous call to
  395.    fgetpos.  */
  396. extern int fsetpos (FILE *__stream, const fpos_t *__position);
  397.  
  398. /* Return the current file position of the stream 'stream'.
  399.    If a failure occurs, -1 is returned.  */
  400. extern long int ftell (FILE *__stream);
  401.  
  402. /* Positions the stream 'stream' at the beginning of the file.
  403.    Equivalent to fseek (stream, 0, SEEK_SET).  */
  404. extern void rewind (FILE *__stream);
  405.  
  406. /* Clears the end-of-file and error indicators for the stream
  407.    'stream'.  */
  408. extern void clearerr (FILE *__stream);
  409.  
  410. /* Return nonzero if the end-of-file indicator for stream 'stream'
  411.    is set.  */
  412. extern int feof (FILE *__stream);
  413. #define feof(stream) ((stream)->__flag & _IOEOF)
  414.  
  415. /* Return nonzero if the error indicator for the stream 'stream'
  416.    is set.  */
  417. extern int ferror (FILE *__stream);
  418. #define ferror(stream) ((stream)->__flag & _IOERR)
  419.  
  420. /* Print an error message to the stream 'stderr'.
  421.  
  422.    If 'message' is null, the error message corresponding to
  423.    'errno' is printed.  */
  424. extern void perror (const char *__message);
  425.  
  426. /* Extensions to the SharedCLibrary.  */
  427.  
  428. #ifdef __RISCOSIFY
  429.  
  430. #define __RISCOSIFY_STRICT_UNIX_SPECS   0x0001
  431. #define __RISCOSIFY_NO_PROCESS        0x0040
  432. #define __RISCOSIFY_NO_SUFFIX        0x0100
  433. #define __RISCOSIFY_DONT_CHECK_DIR    0x0200
  434. #define __RISCOSIFY_CHECK_DIR_IS_SUFFIX    0x0400
  435. #define __RISCOSIFY_NO_REVERSE_SUFFIX    0x0800
  436. #define __RISCOSIFY_FILETYPE_EXT        0x1000
  437. #define __RISCOSIFY_FILETYPE_FFF_EXT    0x2000
  438. #define __RISCOSIFY_FILETYPE_NOT_SET    0x4000
  439. #define __RISCOSIFY_MASK                0x7F41
  440. #define __RISCOSIFY_FILETYPE_NOTFOUND   -1
  441. #define __RISCOSIFY_FILETYPE_NOTSPECIFIED -1
  442.  
  443. extern char *__riscosify_scl (const char *name, int __create_dir);
  444.  
  445. extern char *__riscosify (const char *__name, int __create_dir,
  446.               int __riscosify_flags,
  447.               char *__buffer, size_t __buf_len,
  448.               int *__filetype);
  449.  
  450. /* Gets the __riscosify_control value which can be defined by
  451.    the global variable __riscosify_control in the user program.
  452.    Returns a copy of __riscosify_control_internal (with a default
  453.    value of 0) when __riscosify_control is not defined.  */
  454. extern int __get_riscosify_control (void);
  455. /* Sets the __riscosify_control value when it's defined.
  456.    Otherwise __riscosify_control_internal gets written.  */
  457. extern void __set_riscosify_control (int __riscosify_flags);
  458.  
  459. #endif
  460.  
  461. /* Return the system file descriptor for stream.  */
  462. extern int fileno (FILE *__stream);
  463. #define fileno(f) ((int)(f))
  464.  
  465. /* Create a new stream that refers to an existing system file descriptor.  */
  466. extern FILE *fdopen (int __fd, const char *__modes);
  467.  
  468.  
  469. #ifdef __cplusplus
  470. }
  471. #endif
  472.  
  473. #endif
  474.