backported fixes from 256boss
[bootcensus] / src / libc / stdio.h
1 /*
2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018-2019  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef STDIO_H_
19 #define STDIO_H_
20
21 #include <stdlib.h>
22 #include <stdarg.h>
23
24 typedef struct FILE FILE;
25
26 #define SEEK_SET        0
27 #define SEEK_CUR        1
28 #define SEEK_END        2
29
30 #define EOF     (-1)
31
32 #define stdin   ((FILE*)0)
33 #define stdout  ((FILE*)1)
34 #define stderr  ((FILE*)2)
35
36 int putchar(int c);
37 int puts(const char *s);
38
39 int printf(const char *fmt, ...);
40 int vprintf(const char *fmt, va_list ap);
41
42 int sprintf(char *buf, const char *fmt, ...);
43 int vsprintf(char *buf, const char *fmt, va_list ap);
44
45 int snprintf(char *buf, size_t sz, const char *fmt, ...);
46 int vsnprintf(char *buf, size_t sz, const char *fmt, va_list ap);
47
48 /* TODO */
49 int fprintf(FILE *fp, const char *fmt, ...);
50 int vfprintf(FILE *fp, const char *fmt, va_list ap);
51
52 /* TODO
53 int fscanf(FILE *fp, const char *fmt, ...);
54 int vfscanf(FILE *fp, const char *fmt, va_list ap);
55
56 int sscanf(const char *str, const char *fmt, ...);
57 int vsscanf(const char *ptr, const char *fmt, va_list ap);
58 */
59
60 /* printf to the serial port */
61 int ser_printf(const char *fmt, ...);
62 int ser_vprintf(const char *fmt, va_list ap);
63
64 void perror(const char *s);
65
66
67 /* FILE I/O */
68 FILE *fopen(const char *path, const char *mode);
69 int fclose(FILE *fp);
70
71 long filesize(FILE *fp);
72 int fseek(FILE *fp, long offset, int from);
73 void rewind(FILE *fp);
74 long ftell(FILE *fp);
75
76 size_t fread(void *buf, size_t size, size_t count, FILE *fp);
77 size_t fwrite(const void *buf, size_t size, size_t count, FILE *fp);
78
79 int fgetc(FILE *fp);
80 char *fgets(char *buf, int size, FILE *fp);
81
82 int fputc(int c, FILE *fp);
83
84 int fflush(FILE *fp);
85
86 int feof(FILE *fp);
87 int ferror(FILE *fp);
88 void clearerr(FILE *fp);
89
90 #endif  /* STDIO_H_ */