forked from phoenix-rtos/libphoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdio.h
332 lines (205 loc) · 8.71 KB
/
stdio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* Phoenix-RTOS
*
* libphoenix
*
* stdio.h
*
* Copyright 2017-2018 Phoenix Systems
* Author: Pawel Pisarczyk, Kamil Amanowicz, Michal Miroslaw, Aleksander Kaminski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#ifndef _LIBPHOENIX_STDIO_H_
#define _LIBPHOENIX_STDIO_H_
#include <arch.h>
#include <stdarg.h>
#include <sys/types.h>
#ifndef NOMMU
#define BUFSIZ SIZE_PAGE
#else
#define BUFSIZ 16
#endif
#define EOF (-1)
#define FILENAME_MAX 128
#define _IOFBF 0x2000
#define _IOLBF 0x4000
#define _IONBF 0x8000
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
typedef offs_t fpos_t;
typedef struct _FILE {
int fd;
unsigned flags;
int mode;
size_t bufeof;
size_t bufpos;
size_t bufsz;
char *buffer;
handle_t lock;
} FILE;
typedef struct _DIR {
oid_t oid;
size_t pos;
struct dirent *dirent;
} DIR;
typedef struct _IO_cookie_io_functions
{
void *read;
void *write;
void *seek;
void *close;
} cookie_io_functions_t;
extern FILE *stderr, *stdin, *stdout;
/* Closes the stream. All buffers are flushed. */
extern int fclose(FILE *file);
/* Clears the end-of-file and error indicators for the given stream. */
extern void clearerr(FILE *stream);
/* Tests the end-of-file indicator for the given stream. */
extern int feof_unlocked(FILE *stream);
/* Tests the end-of-file indicator for the given stream. */
extern int feof(FILE *stream);
/* Tests the error indicator for the given stream. */
extern int ferror(FILE *stream);
extern int ferror_unlocked(FILE *stream);
/* Flushes the output buffer of a stream. */
extern int fflush(FILE *stream);
extern int fflush_unlocked(FILE *stream);
/* Gets the current file position of the stream and writes it to pos. */
extern int fgetpos(FILE *stream, fpos_t *pos);
/* Opens the filename pointed to by filename using the given mode. */
extern FILE *fopen(const char *filename, const char *mode);
extern FILE *fopen_unlocked(const char *filename, const char *mode);
/* Associates a stream with existing file descriptor fd. */
extern FILE *fdopen(int fd, const char *mode);
/* Reads data from the given stream into the array pointed to by ptr. */
extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
extern size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream);
/* Associates a new filename with the given open stream and same time closing the old file in stream. */
extern FILE *freopen(const char *filename, const char *mode, FILE *stream);
/* examines the argument stream and returns its integer file descriptor */
extern int fileno(FILE *stream);
extern int fileno_unlocked(FILE *stream);
/*
* Sets the file position of the stream to the given offset. The argument offset signifies the number of bytes
* to seek from the given whence position.
*/
extern int fseek(FILE *stream, long int offset, int whence);
extern int fseek_unlocked(FILE *stream, long int offset, int whence);
extern int fseeko(FILE *stream, off_t offset, int whence);
/*
* Sets the file position of the given stream to the given position. The argument pos is a position given by
* the function fgetpos.
*/
extern int fsetpos(FILE *stream, const fpos_t *pos);
/* Returns the current file position of the given stream. */
extern long int ftell(FILE *stream);
extern off_t ftello(FILE *stream);
/* Writes data from the array pointed to by ptr to the given stream. */
extern size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
extern size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream);
/* Deletes the given filename so that it is no longer accessible. */
extern int remove(const char *filename);
/* Causes the filename referred to, by old_filename to be changed to new_filename. */
extern int rename(const char *old_filename, const char *new_filename);
/* Sets the file position to the beginning of the file of the given stream. */
extern void rewind(FILE *stream);
/* Defines how a stream should be buffered. */
extern void setbuf(FILE *stream, char *buffer);
/* Another function to define how a stream should be buffered. */
extern int setvbuf(FILE *stream, char *buffer, int mode, size_t size);
/* Creates a temporary file in binary update mode (wb+). */
extern FILE *tmpfile(void);
/* Generates and returns a valid temporary filename which does not exist. */
extern char *tmpnam(char *str);
/* Sends formatted output to a stream. */
extern int fprintf(FILE *stream, const char *format, ...);
/* Sends formatted outout to a file descriptor. */
extern int dprintf(int fd, const char *format, ...);
/* Sends formatted output to stdout. */
extern int printf(const char *format, ...);
/* Sends formatted output to a string. */
extern int sprintf(char *str, const char *format, ...);
/* Sends formatted output to a string. */
extern int snprintf(char *str, size_t n, const char *format, ...);
/* Sends formatted output to a stream using an argument list. */
extern int vfprintf(FILE *stream, const char *format, va_list arg);
/* Sends formatted output to stdout using an argument list. */
extern int vprintf(const char *format, va_list arg);
/* Sends formatted output to a string using an argument list. */
extern int vsprintf(char *str, const char *format, va_list arg);
/* Sends formatted output to a string using an argument list. */
extern int vsnprintf(char *str, size_t n, const char *format, va_list arg);
/* Print formatted output to allocated string. */
extern int asprintf(char **strp, const char *fmt, ...);
/* Print formatted output to allocated string using an argument list. */
extern int vasprintf(char **strp, const char *fmt, va_list ap);
/* Reads formatted input from a stream. */
extern int fscanf(FILE *stream, const char *format, ...);
/* Reads formatted input from stdin. */
extern int scanf(const char *format, ...);
/* Reads formatted input from a string. */
extern int sscanf(const char *str, const char *format, ...);
/* Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream. */
extern int fgetc(FILE *stream);
/*
* Reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read,
* the newline character is read, or the end-of-file is reached, whichever comes first.
*/
extern char *fgets(char *str, int n, FILE *stream);
extern char *fgets_unlocked(char *s, int n, FILE *stream);
/*
* Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position
* indicator for the stream.
*/
extern int fputc(int c, FILE *stream);
extern int fputc_unlocked(int c, FILE *stream);
/* Writes a string to the specified stream up to but not including the null character. */
extern int fputs(const char *str, FILE *stream);
extern int fputs_unlocked(const char *s, FILE *stream);
/* Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream. */
extern int getc(FILE *stream);
extern int getc_unlocked(FILE *stream);
/* Gets a character (an unsigned char) from stdin. */
extern int getchar(void);
extern int getchar_unlocked(void);
/* Pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations */
extern int ungetc(int c, FILE *stream);
/*
* Reads a line from stdin and stores it into the string pointed to by, str. It stops when either the newline character is read
* or when the end-of-file is reached, whichever comes first.
*/
extern char *gets(char *str);
/*
* Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator
* for the stream.
*/
extern int putc(int c, FILE *stream);
extern int putc_unlocked(int c, FILE *stream);
/* Writes a character (an unsigned char) specified by the argument char to stdout. */
extern int putchar(int c);
extern int putchar_unlocked(int c);
/* Writes a string to stdout up to but not including the null character. A newline character is appended to the output. */
extern int puts(const char *str);
/* Pushes the character char (an unsigned char) onto the specified stream so that the next character is read. */
extern int ungetc(int c, FILE *stream);
extern int ungetc_unlocked(int c, FILE *stream);
/* Prints a descriptive error message to stderr. First the string str is printed followed by a colon and then a space. */
extern void perror(const char *str);
extern FILE *popen(const char *command, const char *type);
extern int pclose(FILE *stream);
extern ssize_t getline(char **lineptr, size_t *n, FILE *stream);
extern void _file_init(void);
/* stdio locking functions */
extern void flockfile(FILE *file);
extern void funlockfile(FILE *file);
#endif