scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

stdio.h (4259B)


      1 #ifndef _STDIO_H
      2 #define _STDIO_H
      3 
      4 #define _NEED_NULL
      5 #define _NEED_SIZET
      6 #define _NEED_VA_LIST
      7 #include <sys/stdio.h>
      8 #include <arch/cdefs.h>
      9 
     10 #ifndef FOPEN_MAX
     11 #define FOPEN_MAX 12
     12 #endif
     13 
     14 #define EOF     -1
     15 #define SEEK_SET 0
     16 #define SEEK_CUR 1
     17 #define SEEK_END 2
     18 
     19 /**
     20  * enum _file_flags - internal FILE macros used by stdio
     21  * @_IOWRITE: write only stream
     22  * @_IOREAD: read only stream
     23  * @_IORW: read and write stream
     24  * @_IOEOF: mark of end of file in the stream
     25  * @_IOERR: mark of error in the stream
     26  * @_IOSTRG: string stream
     27  * @_IOTXT: text stream
     28  * @_IOFBF: full buffered stream
     29  * @_IOLBF: line buffered stream
     30  * @_IONBF: non buffered stream
     31  * @_IOALLOC: stream with a dynamic allocated buffer
     32  */
     33 enum _file_flags {
     34 	_IOWRITE = (1 << 0),
     35 	_IOREAD =  (1 << 1),
     36 	_IORW =    (1 << 2),
     37 	_IOEOF =   (1 << 3),
     38 	_IOERR =   (1 << 4),
     39 	_IOSTRG =  (1 << 5),
     40 	_IOTXT =   (1 << 6),
     41 	_IOFBF =   (1 << 7),
     42 	_IOLBF =   (1 << 8),
     43 	_IONBF =   (1 << 9),
     44 	_IOALLOC = (1 <<10),
     45 };
     46 
     47 /**
     48  * struct FILE - opaque structure containing information about a file
     49  * @fd: file descriptor
     50  * @buf: pointer to i/o buffer
     51  * @rp: read pointer
     52  * @wp: write pointer
     53  * @lp: write pointer used when line-buffering
     54  * @len: actual length of buffer
     55  * @flags: file open mode
     56  * @unbuf: tiny buffer for unbuffered i/o
     57  */
     58 typedef struct _FILE {
     59 	int fd;
     60 	unsigned char *buf;
     61 	unsigned char *rp;
     62 	unsigned char *wp;
     63 	unsigned char *lp;
     64 	size_t len;
     65 	unsigned short flags;
     66 	unsigned char unbuf[1];
     67 } FILE;
     68 
     69 extern FILE __iob[FOPEN_MAX];
     70 
     71 #define	stdin  (&__iob[0])
     72 #define	stdout (&__iob[1])
     73 #define	stderr (&__iob[2])
     74 
     75 extern int remove(const char *);
     76 extern int rename(const char *, const char *);
     77 extern FILE *tmpfile(void);
     78 extern char *tmpnam(char *);
     79 extern int fclose(FILE *);
     80 extern int fflush(FILE *);
     81 extern FILE *fopen(const char *restrict, const char *restrict);
     82 extern FILE *freopen(const char *restrict, const char *restrict,
     83                      FILE *restrict);
     84 extern void setbuf(FILE *restrict, char *restrict);
     85 extern int setvbuf(FILE *restrict, char *restrict, int, size_t);
     86 extern int fprintf(FILE *restrict, const char *restrict, ...);
     87 extern int fscanf(FILE *restrict, const char *restrict, ...);
     88 extern int printf(const char *restrict, ...);
     89 extern int scanf(const char *restrict, ...);
     90 extern int snprintf(char *restrict, size_t, const char *restrict, ...);
     91 extern int sprintf(char *restrict, const char *restrict, ...);
     92 extern int sscanf(const char *restrict, const char *restrict, ...);
     93 
     94 extern int vfprintf(FILE *restrict, const char *restrict, __va_list);
     95 extern int vfscanf(FILE *restrict, const char *restrict, __va_list);
     96 extern int vprintf(const char *restrict, __va_list);
     97 extern int vscanf(const char *restrict, __va_list);
     98 extern int vsnprintf(char *restrict, size_t, const char *restrict, __va_list);
     99 extern int vsprintf(char *restrict, const char *restrict, __va_list);
    100 extern int vsscanf(const char *restrict, const char *restrict, __va_list);
    101 
    102 extern int fgetc(FILE *);
    103 extern char *fgets(char *restrict, int, FILE *restrict);
    104 extern int fputc(int, FILE *);
    105 extern int fputs(const char *restrict, FILE *restrict);
    106 extern int getc(FILE *);
    107 extern int getchar(void);
    108 extern char *gets(char *);
    109 extern int putc(int, FILE *);
    110 extern int putchar(int);
    111 extern int puts(const char *);
    112 extern int ungetc(int, FILE *);
    113 extern size_t fread(void *restrict, size_t, size_t, FILE *restrict);
    114 extern size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
    115 extern int fseek(FILE *, long int, int);
    116 extern long int ftell(FILE *);
    117 extern void rewind(FILE *);
    118 extern void clearerr(FILE *);
    119 extern int feof(FILE *);
    120 extern int ferror(FILE *);
    121 extern void perror(const char *);
    122 
    123 extern int __getc(FILE *);
    124 extern int __putc(int, FILE *);
    125 
    126 #define getc(fp)            ((fp)->rp >= (fp)->wp ? __getc(fp) : *(fp)->rp++)
    127 #define putc(c, fp)         ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
    128 #define ferror(fp)          ((fp)->flags & _IOERR)
    129 #define feof(fp)            ((fp)->flags & _IOEOF)
    130 #define clearerr(fp)        (void) ((fp)->flags &= ~(_IOERR|_IOEOF))
    131 #define getchar()           getc(stdin)
    132 #define putchar(c)          putc((c), stdout)
    133 #define setbuf(fp, b)       (void) setvbuf(fp, b, b ? _IOFBF:_IONBF, BUFSIZ)
    134 
    135 #endif