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