scc

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

stdio.h (4241B)


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