scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

stdio.h (3750B)


      1 #ifndef _STDIO_H
      2 #define _STDIO_H
      3 
      4 #include <arch/stdio.h>
      5 
      6 #ifndef NULL
      7 #define NULL ((void *) 0)
      8 #endif
      9 
     10 #define EOF            -1
     11 #define _IOFBF          0
     12 #define _IOLBF          1
     13 #define _IONBF          2
     14 #define SEEK_CUR        0
     15 #define SEEK_END        1
     16 #define SEEK_SET        2
     17 
     18 typedef struct {
     19 	int fd;        	/* file descriptor */
     20 	char flags;     /* bits for must free buffer on close, line-buffered */
     21 	char state;     /* last operation was read, write, position, error, eof */
     22 	char *buf;      /* pointer to i/o buffer */
     23 	char *rp;       /* read pointer (or write end-of-buffer) */
     24 	char *wp;       /* write pointer (or read end-of-buffer) */
     25 	char *lp;       /* actual write pointer used when line-buffering */
     26 	size_t len;    /* actual length of buffer */
     27 	char unbuf[1];  /* tiny buffer for unbuffered io */
     28 } FILE;
     29 
     30 extern FILE _IO_stream[FOPEN_MAX];
     31 
     32 #define	stderr	(&_IO_stream[2])
     33 #define	stdin	(&_IO_stream[0])
     34 #define	stdout	(&_IO_stream[1])
     35 
     36 extern int remove(const char *filename);
     37 extern int rename(const char *old, const char *new);
     38 extern FILE *tmpfile(void);
     39 extern char *tmpnam(char *s);
     40 extern int fclose(FILE *fp);
     41 extern int fflush(FILE *fp);
     42 extern FILE *fopen(const char * restrict fname, const char * restrict mode);
     43 extern FILE *freopen(const char * restrict fname, const char * restrict mode,
     44                      FILE * restrict fp);
     45 extern void setbuf(FILE * restrict fp, char * restrict buf);
     46 extern int setvbuf(FILE * restrict fp,
     47                    char * restrict buf, int mode, size_t size);
     48 extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
     49 extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
     50 extern int printf(const char * restrict fmt, ...);
     51 extern int scanf(const char * restrict fmt, ...);
     52 extern int snprintf(char * restrict s,
     53                     size_t n, const char * restrict fmt, ...);
     54 extern int sprintf(char * restrict s, const char * restrict fmt, ...);
     55 extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
     56 
     57 #ifdef _STDARG_H
     58 extern int vfprintf(FILE * restrict fp,
     59                     const char * restrict fmt, va_list arg);
     60 extern int vfscanf(FILE * restrict fp,
     61                    const char * restrict fmt, va_list arg);
     62 extern int vprintf(const char * restrict fmt, va_list arg);
     63 extern int vscanf(const char * restrict fmt, va_list arg);
     64 extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
     65                      va_list arg);
     66 extern int vsprintf(char * restrict s,
     67                     const char * restrict fmt, va_list arg);
     68 extern int vsscanf(const char * restrict s,
     69                    const char * restrict fmt, va_list arg);
     70 #endif
     71 
     72 extern int fgetc(FILE *fp);
     73 extern char *fgets(char * restrict s, int n, FILE * restrict fp);
     74 extern int fputc(int c, FILE *fp);
     75 extern int fputs(const char * restrict s, FILE * restrict fp);
     76 extern int getc(FILE *fp);
     77 extern int getchar(void);
     78 extern char *gets(char *s);
     79 extern int putc(int c, FILE *fp);
     80 extern int putchar(int c);
     81 extern int puts(const char *s);
     82 extern int ungetc(int c, FILE *fp);
     83 extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
     84              FILE * restrict fp);
     85 extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
     86               FILE * restrict fp);
     87 extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
     88 extern int fseek(FILE *fp, long int offset, int whence);
     89 extern int fsetpos(FILE *fp, const fpos_t *pos);
     90 extern long int ftell(FILE *fp);
     91 extern void rewind(FILE *fp);
     92 extern void clearerr(FILE *fp);
     93 extern int feof(FILE *fp);
     94 extern int ferror(FILE *fp);
     95 extern void perror(const char *s);
     96 
     97 #ifdef __USE_MACROS
     98 #define printf(...) fprintf(stdout, __VA_ARGS__)
     99 #endif
    100 
    101 #endif