MicrOS
stdio.h
Go to the documentation of this file.
1 #ifndef STDIO_H
2 #define STDIO_H
3 
5 #define BUFSIZ 1024 * 32
6 
8 #define EOF -1
9 
11 #define FILENAME_MAX 255
12 
14 #define FOPEN_MAX INT32_MAX
15 
17 #define L_tmpnam 0
18 
20 #define TMP_MAX 0
21 
23 #define SEEK_SET 0
24 
26 #define SEEK_CUR 1
27 
29 #define SEEK_END 2
30 
32 #define _IONBF 0
33 
35 #define _IOLBF 1
36 
38 #define _IOFBF 2
39 
40 #include <stdint.h>
41 #include <stdarg.h>
42 #include "stdlib.h"
43 
45 typedef uint32_t size_t;
46 
48 typedef uint32_t fpos_t;
49 
51 typedef enum file_buffering_mode
52 {
55 
58 
62 
63 typedef enum file_mode
64 {
72 } file_mode;
73 
75 
76 typedef struct file
77 {
79  char filename[FILENAME_MAX];
80 
82 
84  char *buffer;
85 
88 
91 
94 
97 
100 
103 
105  int (*fetch)(struct file *file);
106 
108  void (*flush)(struct file *file);
109 } FILE;
110 
112 extern FILE *stdin;
113 
115 extern FILE *stdout;
116 
118 extern FILE *stderr;
119 
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123 
125 /*
126  Deletes the file whose name is specified in \p filename.
127  \param filename C string containing the name of the file to be deleted.<br>
128  Attention: MicrOS requires full file path. Use \p main parameter with path if you want remove file from program folder.
129  \return If the file is successfully deleted, a zero value is returned. On failure, a nonzero value is returned.
130 */
131 int remove(const char *filename);
132 
134 /*
135  Changes the name of the file or directory specified by \p oldname to \p newname.
136  \param oldname C string containing the name of an existing file to be renamed and/or moved.<br>
137  Attention: MicrOS requires full file path. Use \p main parameter with path if you want work on file from program folder.
138  \param newname C string containing the name of an existing file to be renamed and/or moved.<br>
139  Attention: MicrOS requires here only new filename without leading path.
140  \return If the file is successfully renamed, a zero value is returned. On failure, a nonzero value is returned.
141 */
142 int rename(const char *oldname, const char *newname);
143 
145 
151 FILE *fopen(const char *filename, const char *mode);
152 
154 
161 FILE *freopen(const char *filename, const char *mode, FILE *stream);
162 
164 
169 int fclose(FILE *stream);
170 
172 
177 int fflush(FILE *stream);
178 
180 
185 void setbuf(FILE *stream, char *buffer);
186 
188 
196 int setvbuf(FILE *stream, char *buffer, int mode, size_t size);
197 
199 
204 int fgetc(FILE *stream);
205 
207 
214 char *fgets(char *str, int num, FILE *stream);
215 
217 
223 int fputc(int character, FILE *stream);
224 
226 
232 int fputs(const char *str, FILE *stream);
233 
235 
240 int getc(FILE *stream);
241 
243 
247 int getchar();
248 
250 
255 char *gets(char *str);
256 
258 
264 int putc(int character, FILE *stream);
265 
267 
272 int putchar(int character);
273 
275 
280 int puts(const char *str);
281 
283 
289 int ungetc(int character, FILE *stream);
290 
292 
300 size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
301 
303 
311 size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
312 
314 
320 int fgetpos(FILE *stream, fpos_t *pos);
321 
323 
330 int fseek(FILE *stream, long int offset, int origin);
331 
333 
339 int fsetpos(FILE *stream, const fpos_t *pos);
340 
342 
347 long int ftell(FILE *stream);
348 
350 
354 void rewind(FILE *stream);
355 
357 
361 void clearerr(FILE *stream);
362 
364 
369 int feof(FILE *stream);
370 
372 
377 int ferror(FILE *stream);
378 
380 /*
381  Interprets the value of \p errno as an error message, and prints it to \p stderr
382  (the standard error output stream, usually the console), optionally preceding it with the custom message specified in \p str.
383  \param str C string containing a custom message to be printed before the error message itself.
384 */
385 void perror(const char *str);
386 
388 
395 int sprintf(char *str, const char *format, ...);
396 
398 
404 int printf(const char *format, ...);
405 
407 
414 int fprintf(FILE *file, const char *format, ...);
415 
417 
424 int vfprintf(FILE *stream, const char *format, va_list arg);
425 
427 
433 int vprintf(const char *format, va_list arg);
434 
436 
443 int vsprintf(char *str, const char *format, va_list arg);
444 
446 
453 int vfscanf(FILE *stream, const char *format, va_list arg);
454 
456 
462 int scanf(const char *format, ...);
463 
465 
470 
472 
476 file_mode __stdio_get_file_mode(const char *str_mode);
477 
478 #ifdef __cplusplus
479 }
480 #endif
481 
482 #endif
file_mode __stdio_get_file_mode(const char *str_mode)
Parses file mode.
Definition: stdio.c:20
file_mode mode
Definition: stdio.h:81
uint32_t size
Position of the buffer end in the stream.
Definition: stdio.h:93
Definition: stdio.h:67
void perror(const char *str)
Print error message.
Definition: perror.c:6
Definition: stdio.h:71
int feof(FILE *stream)
Check end-of-file indicator.
Definition: feof.c:3
Definition: stdio.h:68
int fseek(FILE *stream, long int offset, int origin)
Reposition stream position indicator.
Definition: fseek.c:3
size_t fread(void *ptr, size_t size, size_t count, FILE *stream)
Read block of data from stream.
Definition: fread.c:3
int setvbuf(FILE *stream, char *buffer, int mode, size_t size)
Change stream buffering.
Definition: setvbuf.c:3
int vfscanf(FILE *stream, const char *format, va_list arg)
Read formatted data from stream into variable argument list.
Definition: vfscanf.c:211
#define FILENAME_MAX
Maximum length of file names.
Definition: stdio.h:11
FILE * freopen(const char *filename, const char *mode, FILE *stream)
Reopen stream with different file or mode.
Definition: freopen.c:5
int vprintf(const char *format, va_list arg)
Print formatted data from variable argument list to stdout.
Definition: vprintf.c:4
int fputc(int character, FILE *stream)
Write character to stream.
Definition: fputc.c:3
int fputs(const char *str, FILE *stream)
Write string to stream.
Definition: fputs.c:3
Flush if buffer is full, new line char is present or fflush has been called.
Definition: stdio.h:57
int fflush(FILE *stream)
Flush stream.
Definition: fflush.c:3
void clearerr(FILE *stream)
Clear error indicators.
Definition: clearerr.c:3
int getchar()
Get character from stdin.
Definition: getchar.c:3
char * buffer
Stream buffer.
Definition: stdio.h:84
int fsetpos(FILE *stream, const fpos_t *pos)
Set position indicator of stream.
Definition: fsetpos.c:3
FILE * __stdio_create_stream()
Creates new stream.
Definition: stdio.c:7
FILE * fopen(const char *filename, const char *mode)
Open file.
Definition: fopen.c:5
int vfprintf(FILE *stream, const char *format, va_list arg)
Print formatted data from variable argument list to stream.
Definition: vfprintf.c:550
int puts(const char *str)
Write string to stdout.
Definition: puts.c:3
int sprintf(char *str, const char *format,...)
Write formatted data to string.
Definition: sprintf.c:4
Object containing information to control a stream.
Definition: stdio.h:76
uint32_t error
Error code.
Definition: stdio.h:99
Definition: stdio.h:66
int getc(FILE *stream)
Get character from stream.
Definition: getc.c:3
char * fgets(char *str, int num, FILE *stream)
Get string from stream.
Definition: fgets.c:3
void setbuf(FILE *stream, char *buffer)
Set stream buffer.
Definition: setbuf.c:3
uint32_t fpos_t
Object containing information to specify a position within a file.
Definition: stdio.h:48
void rewind(FILE *stream)
Set position of stream to the beginning.
Definition: rewind.c:3
char * gets(char *str)
Get string from stdin.
Definition: gets.c:3
int fprintf(FILE *file, const char *format,...)
Print formatted data to stdoutWrite formatted data to stream.
Definition: fprintf.c:4
uint32_t base
Position of the buffer start in the stream.
Definition: stdio.h:87
FILE * stdout
Standard output (default is console).
Definition: stdio.c:4
int fgetc(FILE *stream)
Get character from stream.
Definition: fgetc.c:3
uint32_t limit
Total size of the stream (can be 0 if it&#39;s undefined like console or keyboard).
Definition: stdio.h:96
int printf(const char *format,...)
Print formatted data to stdout.
Definition: printf.c:4
Definition: stdio.h:69
Definition: stdio.h:70
int putc(int character, FILE *stream)
Write character to stream.
Definition: putc.c:3
int scanf(const char *format,...)
Read formatted data from stdin.
Definition: scanf.c:4
FILE * stdin
Standard input (default is keyboard).
Definition: stdio.c:3
Flush when new data is present (don&#39;t store it in buffer).
Definition: stdio.h:54
FILE * stderr
Standard error output (default is console).
Definition: stdio.c:5
Definition: stdio.h:65
int fclose(FILE *stream)
Close file.
Definition: fclose.c:3
int ungetc(int character, FILE *stream)
Unget character from stream.
Definition: ungetc.c:3
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream)
Write block of data to stream.
Definition: fwrite.c:3
file_buffering_mode
Stream buffering modest.
Definition: stdio.h:51
Flush if buffer is full or fflush has been called.
Definition: stdio.h:60
int ferror(FILE *stream)
Check error indicator.
Definition: ferror.c:3
file_buffering_mode buffering_mode
Buffering mode of the stream.
Definition: stdio.h:102
char buffer[500]
Definition: physical_memory_manager.c:5
file_mode
Definition: stdio.h:63
uint32_t size_t
Unsigned integral type.
Definition: stdio.h:45
int putchar(int character)
Write character to stdout.
Definition: putchar.c:3
long int ftell(FILE *stream)
Get current position in stream.
Definition: ftell.c:3
size_t uint32_t
Unsigned integral type.
Definition: string.h:8
uint32_t pos
Current position in the stream.
Definition: stdio.h:90
int fgetpos(FILE *stream, fpos_t *pos)
Get current position in stream.
Definition: fgetpos.c:3
static char mode
Definition: vga_gmode.c:20
int vsprintf(char *str, const char *format, va_list arg)
Print formatted data from variable argument list to string.
Definition: vsprintf.c:4
int rename(const char *oldname, const char *newname)
Rename file.
Definition: rename.c:4