Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
stdio.h
Go to the documentation of this file.
1 #ifndef STDIO_H__
2 #define STDIO_H__
3 
4 #include <printf.h>
5 #include <stdarg.h>
6 #include <stddef.h>
7 #include <wctype.h> //TODO: eliminate need for this header here (refactor types?)
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif //__cplusplus
12 
19 
20 #pragma mark - Definitions -
21 
22 #undef EOF
23 #define EOF (-1)
24 
25 typedef union _G_fpos64_t
26 {
27  char __opaque[16];
28  long long __lldata;
29  double __align;
30 } fpos_t;
31 
32 /*
33  * Stdio buffers.
34  */
35 struct __sbuf
36 {
37  unsigned char* _base;
38  int _size;
39 };
40 
41 /*
42  * struct __sFILE_fake is the start of a struct __sFILE, with only the
43  * minimal fields allocated. In __sinit() we really allocate the 3
44  * standard streams, etc., and point away from this fake.
45  */
47 {
48  unsigned char* _p; /* current position in (some) buffer */
49  int _r; /* read space left for getc() */
50  int _w; /* write space left for putc() */
51  short _flags; /* flags, below; this FILE is free if 0 */
52  short _file; /* fileno, if Unix descriptor, else -1 */
53  struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
54  int _lbfsize; /* 0 or -_bf._size, for inline putc */
55 
56  struct _reent* _data;
57 };
58 
59 #if !defined(__FILE_defined)
60 typedef struct __sFILE_fake FILE;
61 #define __FILE_defined
62 #endif
63 
64 #pragma mark - Supported Functions -
65 
67 int putchar(int c);
68 int puts(const char*);
69 
70 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
71 int asprintf(char**, const char*, ...);
72 int vasprintf(char**, const char*, __isoc_va_list);
73 #endif
74 
75 #pragma mark - Unsupported Functions -
76 
77 #ifndef DISABLE_UNIMPLEMENTED_LIBC_APIS
78 
79 int fseek(FILE*, long, int);
80 long ftell(FILE*);
81 void rewind(FILE*);
82 
83 int fgetpos(FILE* __restrict, fpos_t* __restrict);
84 int fsetpos(FILE*, const fpos_t*);
85 
86 size_t fread(void* __restrict, size_t, size_t, FILE* __restrict);
87 size_t fwrite(const void* __restrict, size_t, size_t, FILE* __restrict);
88 
89 char* fgets(char* __restrict, int, FILE* __restrict);
90 #if __STDC_VERSION__ < 201112L
91 char* gets(char*);
92 #endif
93 
94 int fputc(int, FILE*);
95 int putc(int, FILE*);
96 
97 wchar_t* fgetws(wchar_t* __restrict, int, FILE* __restrict);
98 int fputws(const wchar_t* __restrict, FILE* __restrict);
99 
100 int fgetc(FILE*);
101 int getc(FILE*);
102 int getchar(void);
103 int ungetc(int, FILE*);
104 
105 wint_t fgetwc(FILE*);
106 wint_t getwc(FILE*);
107 wint_t getwchar(void);
109 
110 wint_t fputwc(wchar_t, FILE*);
111 wint_t putwc(wchar_t, FILE*);
112 wint_t putwchar(wchar_t);
113 
114 char* tmpnam(char*);
115 FILE* tmpfile(void);
116 
117 int fwide(FILE*, int);
118 
119 int fputs(const char* __restrict, FILE* __restrict);
120 
121 FILE* fopen(const char* __restrict, const char* __restrict);
122 FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict);
123 int fclose(FILE*);
124 
125 int feof(FILE*);
126 int ferror(FILE*);
127 int fflush(FILE*);
128 void clearerr(FILE*);
129 
130 int remove(const char*);
131 int rename(const char*, const char*);
132 
133 int setvbuf(FILE* __restrict, char* __restrict, int, size_t);
134 void setbuf(FILE* __restrict, char* __restrict);
135 
136 int scanf(const char* __restrict, ...);
137 int fscanf(FILE* __restrict, const char* __restrict, ...);
138 int sscanf(const char* __restrict, const char* __restrict, ...);
139 int vscanf(const char* __restrict, __isoc_va_list);
140 int vfscanf(FILE* __restrict, const char* __restrict, __isoc_va_list);
141 int vsscanf(const char* __restrict, const char* __restrict, __isoc_va_list);
142 int wscanf(const wchar_t* __restrict, ...);
143 int fwscanf(FILE* __restrict, const wchar_t* __restrict, ...);
144 int swscanf(const wchar_t* __restrict, const wchar_t* __restrict, ...);
145 int vwscanf(const wchar_t* __restrict, __isoc_va_list);
146 int vfwscanf(FILE* __restrict, const wchar_t* __restrict, __isoc_va_list);
147 int vswscanf(const wchar_t* __restrict, const wchar_t* __restrict, __isoc_va_list);
148 
150 
151 void perror(const char*);
152 
153 int wprintf(const wchar_t* __restrict, ...);
154 int fprintf(FILE* __restrict, const char* __restrict, ...);
155 int vprintf(const char* __restrict, __isoc_va_list);
156 int vfprintf(FILE* __restrict, const char* __restrict, __isoc_va_list);
157 int vsprintf(char* __restrict, const char* __restrict, __isoc_va_list);
158 int fwprintf(FILE* __restrict, const wchar_t* __restrict, ...);
159 int swprintf(wchar_t* __restrict, size_t, const wchar_t* __restrict, ...);
160 int vwprintf(const wchar_t* __restrict, __isoc_va_list);
161 int vfwprintf(FILE* __restrict, const wchar_t* __restrict, __isoc_va_list);
162 int vswprintf(wchar_t* __restrict, size_t, const wchar_t* __restrict, __isoc_va_list);
163 #endif
164 
165 #ifdef __cplusplus
166 }
167 #endif //__cplusplus
168 
169 #endif // STDIO_H__
unsigned wint_t
Definition: wctype.h:11
int _w
Definition: stdio.h:50
int getc(FILE *)
int putc(int, FILE *)
int putchar(int c)
Requires a definition of _putchar() for your platform.
Definition: putchar.c:4
int swprintf(wchar_t *__restrict, size_t, const wchar_t *__restrict,...)
int puts(const char *)
Definition: puts.c:3
unsigned char * _base
Definition: stdio.h:37
void perror(const char *)
Unsupported printf variants.
short _flags
Definition: stdio.h:51
wint_t fputwc(wchar_t, FILE *)
int _lbfsize
Definition: stdio.h:54
int vswprintf(wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list)
int fclose(FILE *)
int _r
Definition: stdio.h:49
int scanf(const char *__restrict,...)
int fwprintf(FILE *__restrict, const wchar_t *__restrict,...)
int wscanf(const wchar_t *__restrict,...)
int fsetpos(FILE *, const fpos_t *)
double __align
Definition: stdio.h:29
int vprintf(const char *__restrict, __isoc_va_list)
size_t fread(void *__restrict, size_t, size_t, FILE *__restrict)
struct _reent * _data
Definition: stdio.h:56
char * gets(char *)
int fscanf(FILE *__restrict, const char *__restrict,...)
FILE * freopen(const char *__restrict, const char *__restrict, FILE *__restrict)
int fseek(FILE *, long, int)
int fputws(const wchar_t *__restrict, FILE *__restrict)
long ftell(FILE *)
char * tmpnam(char *)
char * fgets(char *__restrict, int, FILE *__restrict)
int feof(FILE *)
int wprintf(const wchar_t *__restrict,...)
wint_t getwc(FILE *)
wint_t putwc(wchar_t, FILE *)
int rename(const char *, const char *)
int sscanf(const char *__restrict, const char *__restrict,...)
int remove(const char *)
wint_t putwchar(wchar_t)
wint_t getwchar(void)
struct __sbuf _bf
Definition: stdio.h:53
Definition: stdio.h:35
int getchar(void)
FILE * fopen(const char *__restrict, const char *__restrict)
int vwprintf(const wchar_t *__restrict, __isoc_va_list)
char __opaque[16]
Definition: stdio.h:27
int vswscanf(const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list)
void setbuf(FILE *__restrict, char *__restrict)
int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list)
int fwscanf(FILE *__restrict, const wchar_t *__restrict,...)
int swscanf(const wchar_t *__restrict, const wchar_t *__restrict,...)
size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict)
unsigned char * _p
Definition: stdio.h:48
short _file
Definition: stdio.h:52
int ungetc(int, FILE *)
FILE * tmpfile(void)
int fgetc(FILE *)
wint_t ungetwc(wint_t, FILE *)
int ferror(FILE *)
int _size
Definition: stdio.h:38
int fprintf(FILE *__restrict, const char *__restrict,...)
int fputc(int, FILE *)
int vfwprintf(FILE *__restrict, const wchar_t *__restrict, __isoc_va_list)
int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list)
wchar_t * fgetws(wchar_t *__restrict, int, FILE *__restrict)
int vfwscanf(FILE *__restrict, const wchar_t *__restrict, __isoc_va_list)
int vwscanf(const wchar_t *__restrict, __isoc_va_list)
int asprintf(char **string, const char *fmt,...)
Definition: asprintf.c:7
int fwide(FILE *, int)
int vasprintf(char **string, const char *fmt, va_list arg_list)
Definition: vasprintf.c:8
__builtin_va_list __isoc_va_list
Definition: stdarg.h:14
int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list)
wint_t fgetwc(FILE *)
int setvbuf(FILE *__restrict, char *__restrict, int, size_t)
union _G_fpos64_t fpos_t
long long __lldata
Definition: stdio.h:28
int vscanf(const char *__restrict, __isoc_va_list)
int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list)
int fgetpos(FILE *__restrict, fpos_t *__restrict)
void clearerr(FILE *)
int fflush(FILE *)
void rewind(FILE *)
int fputs(const char *__restrict, FILE *__restrict)