scc

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

stdio.h (4443B)


      1 #ifndef _STDIO_H
      2 #define _STDIO_H
      3 
      4 #define _NEED_NULL
      5 #define _NEED_SIZET
      6 #include <arch/cdefs.h>
      7 #include <arch/stdio.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 #define _IOWRITE        (1 << 0)
     20 #define _IOREAD         (1 << 1)
     21 #define _IORW           (1 << 2)
     22 #define _IOEOF          (1 << 3)
     23 #define _IOERR          (1 << 4)
     24 #define _IOSTRG         (1 << 5)
     25 #define _IOTXT          (1 << 6)
     26 #define _IOFBF          (1 << 7)
     27 #define _IOLBF          (1 << 8)
     28 #define _IONBF          (1 << 9)
     29 #define _IOALLOC        (1 <<10)
     30 
     31 typedef struct {
     32 	int fd;        	        /* file descriptor */
     33 	unsigned char *buf;     /* pointer to i/o buffer */
     34 	unsigned char *rp;      /* read pointer */
     35 	unsigned char *wp;      /* write pointer */
     36 	unsigned char *lp;      /* write pointer used when line-buffering */
     37 	size_t len;             /* actual length of buffer */
     38 	unsigned short flags;
     39 	unsigned char unbuf[1];  /* tiny buffer for unbuffered io */
     40 } FILE;
     41 
     42 extern FILE __iob[FOPEN_MAX];
     43 
     44 #define	stdin	(&__iob[0])
     45 #define	stdout	(&__iob[1])
     46 #define	stderr	(&__iob[2])
     47 
     48 extern int remove(const char *filename);
     49 extern int rename(const char *old, const char *new);
     50 extern FILE *tmpfile(void);
     51 extern char *tmpnam(char *s);
     52 extern int fclose(FILE *fp);
     53 extern int fflush(FILE *fp);
     54 extern FILE *fopen(const char * restrict fname, const char * restrict mode);
     55 extern FILE *freopen(const char * restrict fname, const char * restrict mode,
     56                      FILE * restrict fp);
     57 extern void setbuf(FILE * restrict fp, char * restrict buf);
     58 extern int setvbuf(FILE * restrict fp,
     59                    char * restrict buf, int mode, size_t size);
     60 extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
     61 extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
     62 extern int printf(const char * restrict fmt, ...);
     63 extern int scanf(const char * restrict fmt, ...);
     64 extern int snprintf(char * restrict s,
     65                     size_t n, const char * restrict fmt, ...);
     66 extern int sprintf(char * restrict s, const char * restrict fmt, ...);
     67 extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
     68 
     69 #ifdef _STDARG_H
     70 extern int vfprintf(FILE * restrict fp,
     71                     const char * restrict fmt, va_list arg);
     72 extern int vfscanf(FILE * restrict fp,
     73                    const char * restrict fmt, va_list arg);
     74 extern int vprintf(const char * restrict fmt, va_list arg);
     75 extern int vscanf(const char * restrict fmt, va_list arg);
     76 extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
     77                      va_list arg);
     78 extern int vsprintf(char * restrict s,
     79                     const char * restrict fmt, va_list arg);
     80 extern int vsscanf(const char * restrict s,
     81                    const char * restrict fmt, va_list arg);
     82 #endif
     83 
     84 extern int fgetc(FILE *fp);
     85 extern char *fgets(char * restrict s, int n, FILE * restrict fp);
     86 extern int fputc(int c, FILE *fp);
     87 extern int fputs(const char * restrict s, FILE * restrict fp);
     88 extern int getc(FILE *fp);
     89 extern int getchar(void);
     90 extern char *gets(char *s);
     91 extern int putc(int c, FILE *fp);
     92 extern int putchar(int c);
     93 extern int puts(const char *s);
     94 extern int ungetc(int c, FILE *fp);
     95 extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
     96              FILE * restrict fp);
     97 extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
     98               FILE * restrict fp);
     99 extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
    100 extern int fseek(FILE *fp, long int offset, int whence);
    101 extern int fsetpos(FILE *fp, const fpos_t *pos);
    102 extern long int ftell(FILE *fp);
    103 extern void rewind(FILE *fp);
    104 extern void clearerr(FILE *fp);
    105 extern int feof(FILE *fp);
    106 extern int ferror(FILE *fp);
    107 extern void perror(const char *s);
    108 
    109 extern int __getc(FILE *fp);
    110 extern int __putc(int, FILE *fp);
    111 
    112 #define getc(fp)            ((fp)->rp >= (fp)->wp ? __getc(fp) : *(fp)->rp++)
    113 #define putc(c, fp)         ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
    114 
    115 #define ferror(fp)          ((fp)->flags & _IOERR)
    116 #define feof(fp)            ((fp)->flags & _IOEOF)
    117 #define clearerr(fp)        (void) ((fp)->flags &= ~(_IOERR|_IOEOF))
    118 #define getchar()           getc(stdin)
    119 #define putchar(c)          putc((c), stdout)
    120 #define setbuf(fp, b)       (void) setvbuf(fp, b, b ? _IOFBF:_IONBF, BUFSIZ)
    121 
    122 #endif