Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
stdio.h
Go to the documentation of this file.
1 
4 #ifndef __STDIO_H__
5 #define __STDIO_H__
6 
7 #include <pthread.h>
8 #include <stdarg.h>
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <sys/reent.h>
12 #include <sys/types.h>
13 
14 #define SEEK_SET 0
15 #define SEEK_CUR 1
16 #define SEEK_END 2
17 
18 #define EOF (-1)
19 
20 #define fopen _fopen
21 #define fclose _fclose
22 #define fread _fread
23 #define fwrite _fwrite
24 #define fseek _fseek
25 #define ftell _ftell
26 #define rewind _rewind
27 #define fileno _fileno
28 #define freopen _freopen
29 #define fseeko _fseeko
30 #define ftello _ftello
31 #define fputs _fputs
32 #define fputc _fputc
33 #define putchar _putchar
34 #define puts _puts
35 #define fgetc _fgetc
36 #define getchar _getchar
37 #define fgets _fgets
38 #define feof _feof
39 #define ferror _ferror
40 #define clearerr _clearerr
41 #define fflush _fflush
42 #define setvbuf _setvbuf
43 #define setbuf _setbuf
44 
45 /* The two the standard allows to be macros over the calls above */
46 #define putc(c, stream) fputc(c, stream)
47 #define getc(stream) fgetc(stream)
48 
49 /* A stream of Tenok carries no lock, so these are the locked half under
50  * another name. They name the implementations, which a caller cannot redefine
51  */
52 #define getc_unlocked(stream) _fgetc(stream)
53 #define getchar_unlocked() _getchar()
54 #define putc_unlocked(c, stream) _fputc(c, stream)
55 #define putchar_unlocked(c) _putchar(c)
56 #define fputc_unlocked(c, stream) _fputc(c, stream)
57 #define fgetc_unlocked(stream) _fgetc(stream)
58 #define fgets_unlocked(s, size, stream) _fgets(s, size, stream)
59 #define fputs_unlocked(s, stream) _fputs(s, stream)
60 #define fread_unlocked(p, size, n, stream) _fread(p, size, n, stream)
61 #define fwrite_unlocked(p, size, n, stream) _fwrite(p, size, n, stream)
62 #define feof_unlocked(stream) _feof(stream)
63 #define ferror_unlocked(stream) _ferror(stream)
64 #define clearerr_unlocked(stream) _clearerr(stream)
65 #define fflush_unlocked(stream) _fflush(stream)
66 #define fileno_unlocked(stream) _fileno(stream)
67 
68 #define flockfile(stream) ((void) (stream))
69 #define funlockfile(stream) ((void) (stream))
70 #define ftrylockfile(stream) (0)
71 
72 #define __SIZEOF_FILE sizeof(__FILE)
73 
74 typedef union {
75  char __size[__SIZEOF_FILE];
76  uint32_t __align;
77 } FILE;
78 
79 extern FILE *stdin;
80 extern FILE *stdout;
81 extern FILE *stderr;
82 
90 FILE *fopen(const char *pathname, const char *mode);
91 
99 FILE *fdopen(int fd, const char *mode);
100 
110 FILE *freopen(const char *pathname, const char *mode, FILE *stream);
111 
119 int fseeko(FILE *stream, off_t offset, int whence);
120 
127 off_t ftello(FILE *stream);
128 
134 int fclose(FILE *stream);
135 
146 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
147 
159 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
160 
168 int fseek(FILE *stream, long offset, int whence);
169 
175 long ftell(FILE *stream);
176 
182 void rewind(FILE *stream);
183 
190 int fileno(FILE *stream);
191 
198 int rename(const char *oldpath, const char *newpath);
199 
205 int remove(const char *pathname);
206 
214 int printf(const char *format, ...);
215 
224 int fprintf(FILE *stream, const char *format, ...);
225 
234 int dprintf(int fd, const char *format, ...);
235 
244 int sprintf(char *str, const char *format, ...);
245 
255 int snprintf(char *str, size_t size, const char *format, ...);
256 
264 int vprintf(const char *format, va_list ap);
265 
274 int vfprintf(FILE *stream, const char *format, va_list ap);
275 
284 int vdprintf(int fd, const char *format, va_list ap);
285 
295 int vsprintf(char *str, const char *format, va_list ap);
296 
307 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
308 
317 int sscanf(const char *str, const char *format, ...);
318 
327 int vsscanf(const char *str, const char *format, va_list ap);
328 
335 int fputs(const char *s, FILE *stream);
336 
343 int fputc(int c, FILE *stream);
344 
350 int putchar(int c);
351 
357 int puts(const char *s);
358 
364 int fgetc(FILE *stream);
365 
370 int getchar(void);
371 
380 char *fgets(char *s, int size, FILE *stream);
381 
387 int feof(FILE *stream);
388 
394 int ferror(FILE *stream);
395 
400 void clearerr(FILE *stream);
401 
408 int fflush(FILE *stream);
409 
410 /* How a stream may be asked to buffer. Tenok writes every stream straight
411  * through, which is the last of the three
412  */
413 #define _IOFBF 0
414 #define _IOLBF 1
415 #define _IONBF 2
416 
417 /* The size a program is invited to hand setvbuf(), which Tenok does not use */
418 #define BUFSIZ 1024
419 
431 int setvbuf(FILE *stream, char *buf, int mode, size_t size);
432 
439 void setbuf(FILE *stream, char *buf);
440 
441 #endif
int remove(const char *pathname)
Delete a file or an empty directory.
Definition: file.c:397
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Read nmemb items of data, each size bytes long, from the stream pointed to by stream,...
int vdprintf(int fd, const char *format, va_list ap)
Format and print data to a file with argument list.
Definition: printf.c:452
FILE * freopen(const char *pathname, const char *mode, FILE *stream)
Point a stream that is already open at another file, which is how a program replaces one of the stand...
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Write nmemb items of data, each size bytes long, to the stream pointed to by stream,...
char * fgets(char *s, int size, FILE *stream)
Read a line from the stream, the newline included, and terminate it.
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
Format and print data to a buffer with limited size and argument list.
int sprintf(char *str, const char *format,...)
Format and print data to a buffer.
void setbuf(FILE *stream, char *buf)
Ask the stream to buffer what is written to it, the way setvbuf() does, without reporting whether it ...
#define getchar
Read a character from the standard input.
Definition: stdio.h:36
FILE * fopen(const char *pathname, const char *mode)
Open the file whose name is the string pointed to by pathname and associate a stream with it.
int ferror(FILE *stream)
Tell whether the stream has failed.
int rename(const char *oldpath, const char *newpath)
Change the name or the location of a file.
Definition: file.c:387
long ftell(FILE *stream)
Obtain the current value of the file position indicator.
int fseek(FILE *stream, long offset, int whence)
Set the file position indicator for the stream pointed to by stream.
int dprintf(int fd, const char *format,...)
Format and print data to a file.
Definition: printf.c:457
int fputs(const char *s, FILE *stream)
Write a string to the stream, without its terminating null byte.
Definition: wrapper.c:263
int fclose(FILE *stream)
Close the given file stream.
off_t ftello(FILE *stream)
Report where a stream is, as an off_t.
int fseeko(FILE *stream, off_t offset, int whence)
Reposition a stream, with the offset given as an off_t.
int printf(const char *format,...)
Format and print data to the standard output.
Definition: printf.c:473
int feof(FILE *stream)
Tell whether the end of the stream has been reached.
void rewind(FILE *stream)
Set the file position indicator to the beginning of the file.
int vprintf(const char *format, va_list ap)
Format and print data to the standard output with argument list.
Definition: printf.c:468
int vsprintf(char *str, const char *format, va_list ap)
Format and print data to a buffer with argument list.
int fgetc(FILE *stream)
Read a character from the stream.
FILE * fdopen(int fd, const char *mode)
Put a stream on a descriptor that is already open.
Definition: wrapper.c:68
int vsscanf(const char *str, const char *format, va_list ap)
Read from the string what the format says is in it, taking the places to put it from a variable argum...
void clearerr(FILE *stream)
Clear the end of file and the error state of the stream.
int fputc(int c, FILE *stream)
Write a character to the stream.
Definition: wrapper.c:271
int puts(const char *s)
Write a string and a newline to the standard output.
int snprintf(char *str, size_t size, const char *format,...)
Format and print data to a buffer with limited buffer size.
int vfprintf(FILE *stream, const char *format, va_list ap)
Format and print data to a file with argument list.
Definition: printf.c:484
int fprintf(FILE *stream, const char *format,...)
Format and print data to a file.
Definition: printf.c:491
int fflush(FILE *stream)
Hand over what the stream is holding. Tenok does not buffer, so there is never anything to hand over.
int sscanf(const char *str, const char *format,...)
Read from the string what the format says is in it. Only the string half of scanf is here: the stream...
int putchar(int c)
Write a character to the standard output.
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
Ask the stream to buffer what is written to it. Tenok reaches the device on the call that writes,...
int fileno(FILE *stream)
Examine the argument stream and returns the integer file descriptor used to implement this stream.
Definition: stdio.h:74