9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

stdio.h (4427B)


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