scc

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

stdio.h (3815B)


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