rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2008-2013 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #ifndef __STDIO_H |
| 24 | #define __STDIO_H |
| 25 | |
| 26 | #include <compiler.h> |
| 27 | #include <printf.h> |
| 28 | #include <sys/types.h> |
| 29 | |
| 30 | __BEGIN_CDECLS |
| 31 | |
| 32 | typedef struct FILE { |
| 33 | void *ctx; |
| 34 | int (*fputc)(void *ctx, int c); |
| 35 | int (*fputs)(void *ctx, const char *s); |
| 36 | int (*fgetc)(void *ctx); |
| 37 | int (*vfprintf)(void *ctx, const char *fmt, va_list ap); |
| 38 | } FILE; |
| 39 | |
| 40 | extern FILE __stdio_FILEs[]; |
| 41 | |
| 42 | #define stdin (&__stdio_FILEs[0]) |
| 43 | #define stdout (&__stdio_FILEs[1]) |
| 44 | #define stderr (&__stdio_FILEs[2]) |
| 45 | |
| 46 | FILE *fopen(const char *filename, const char *mode); |
| 47 | int fclose(FILE *stream); |
| 48 | size_t fread(void *ptr, size_t size, size_t count, FILE *stream); |
| 49 | size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream); |
| 50 | int fflush(FILE *stream); |
| 51 | int feof(FILE *stream); |
| 52 | |
| 53 | #define SEEK_SET 0 |
| 54 | #define SEEK_CUR 1 |
| 55 | #define SEEK_END 2 |
| 56 | |
| 57 | int fseek(FILE *stream, long offset, int whence); |
| 58 | long ftell(FILE *stream); |
| 59 | |
| 60 | int fputc(int c, FILE *fp); |
| 61 | #define putc(c, fp) fputc(c, fp) |
| 62 | int putchar(int c); |
| 63 | |
| 64 | int fputs(const char *s, FILE *fp); |
| 65 | int puts(const char *str); |
| 66 | |
| 67 | int getc(FILE *fp); |
| 68 | int getchar(void); |
| 69 | |
| 70 | int fprintf(FILE *fp, const char *fmt, ...); |
| 71 | int vfprintf(FILE *fp, const char *fmt, va_list ap); |
| 72 | |
| 73 | int sscanf(const char *buf, const char *fmt, ...); |
| 74 | |
| 75 | __END_CDECLS |
| 76 | |
| 77 | #endif |
| 78 | |