Rev 8793 | Rev 9204 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8687 | turbocat | 1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // \author (c) Marco Paland (info@paland.com) |
||
3 | // 2014-2019, PALANDesign Hannover, Germany |
||
4 | // |
||
5 | // \license The MIT License (MIT) |
||
6 | // |
||
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
8 | // of this software and associated documentation files (the "Software"), to deal |
||
9 | // in the Software without restriction, including without limitation the rights |
||
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
11 | // copies of the Software, and to permit persons to whom the Software is |
||
12 | // furnished to do so, subject to the following conditions: |
||
13 | // |
||
14 | // The above copyright notice and this permission notice shall be included in |
||
15 | // all copies or substantial portions of the Software. |
||
16 | // |
||
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
23 | // THE SOFTWARE. |
||
24 | // |
||
25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on |
||
26 | // embedded systems with a very limited resources. |
||
27 | // Use this instead of bloated standard/newlib printf. |
||
28 | // These routines are thread safe and reentrant. |
||
29 | // |
||
30 | /////////////////////////////////////////////////////////////////////////////// |
||
31 | |||
32 | #ifndef _STDIO_H_ |
||
33 | #define _STDIO_H_ |
||
34 | |||
35 | #include |
||
36 | #include |
||
37 | |||
38 | extern int _FUNC(puts)(const char *str); |
||
39 | extern int _FUNC(printf)(const char* format, ...); |
||
40 | extern int _FUNC(sprintf)(char* buffer, const char* format, ...); |
||
41 | extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); |
||
42 | extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); |
||
43 | extern int _FUNC(vprintf)(const char* format, va_list va); |
||
44 | |||
45 | extern void _FUNC(debug_printf)(const char* format, ...); |
||
46 | |||
47 | typedef size_t fpos_t; |
||
48 | |||
8730 | turbocat | 49 | #define _FILEMODE_R 1 << 0 // Read |
50 | #define _FILEMODE_W 1 << 1 // Write |
||
51 | #define _FILEMODE_A 1 << 2 // Append |
||
8687 | turbocat | 52 | |
53 | typedef struct FILE_s { |
||
54 | char *name; |
||
55 | fpos_t position; |
||
56 | int error; |
||
57 | int eof; |
||
8730 | turbocat | 58 | int mode; // flags _FILEMODE_* |
8687 | turbocat | 59 | int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!) |
60 | } FILE; |
||
61 | |||
62 | #define _IOFBF 0 |
||
63 | #define _IOLBF 1 |
||
64 | #define _IONBF 2 |
||
65 | |||
66 | #define BUFSIZ 1024 |
||
67 | |||
68 | #define EOF -1 |
||
69 | |||
70 | #define FOPEN_MAX 0xffffffff |
||
71 | |||
72 | #define FILENAME_MAX 255 |
||
73 | |||
74 | #define L_tmpnam FILENAME_MAX |
||
75 | |||
76 | #define SEEK_CUR 0 |
||
77 | #define SEEK_END 1 |
||
78 | #define SEEK_SET 2 |
||
79 | |||
80 | #define TMP_MAX FOPEN_MAX |
||
81 | |||
82 | #define stderr (FILE*)3 |
||
83 | #define stdin (FILE*)1 |
||
84 | #define stdout (FILE*)2 |
||
85 | |||
86 | extern int _FUNC(fgetc)(FILE *); |
||
87 | extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict); |
||
88 | extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...); |
||
89 | extern int _FUNC(fputc)(int, FILE *); |
||
90 | extern int _FUNC(fputs)(const char *restrict, FILE *restrict); |
||
91 | extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict); |
||
92 | extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); |
||
93 | extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); |
||
94 | extern int _FUNC(getc)(FILE *); |
||
8730 | turbocat | 95 | #define getc() _FUNC(fgetc)(stdin) |
8687 | turbocat | 96 | extern int _FUNC(getchar)(void); |
97 | extern int _FUNC(printf)(const char *restrict, ...); |
||
8744 | turbocat | 98 | #define putc(ch) _FUNC(fputc)(ch, stdout) |
8687 | turbocat | 99 | extern int _FUNC(puts)(const char *); |
100 | extern int _FUNC(scanf)(const char *restrict, ...); |
||
101 | extern char* _FUNC(gets)(char *str); |
||
8718 | turbocat | 102 | extern int _FUNC(ungetc)(int, FILE *); |
8687 | turbocat | 103 | extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list); |
104 | extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list); |
||
105 | extern int _FUNC(vprintf)(const char *restrict, va_list); |
||
106 | extern int _FUNC(vscanf)(const char *restrict, va_list); |
||
8718 | turbocat | 107 | extern int _FUNC(sscanf)(const char*, const char *restrict, ...); |
8687 | turbocat | 108 | extern int _FUNC(vsscanf)(const char *, const char*, va_list); |
109 | |||
110 | extern int _FUNC(remove)(const char *); |
||
111 | extern int _FUNC(rename)(const char *, const char *); |
||
112 | extern FILE* _FUNC(tmpfile)(void); |
||
113 | extern char* _FUNC(tmpnam)(char *); |
||
114 | |||
115 | extern int _FUNC(fclose)(FILE *); |
||
116 | extern int _FUNC(fflush)(FILE *); |
||
117 | extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict); |
||
118 | extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict); |
||
119 | extern void _FUNC(setbuf)(FILE *restrict, char *restrict); |
||
120 | extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t); |
||
121 | |||
122 | extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict); |
||
123 | extern int _FUNC(fseek)(FILE *, long, int); |
||
124 | extern int _FUNC(fsetpos)(FILE *, const fpos_t *); |
||
125 | extern long _FUNC(ftell)(FILE *); |
||
126 | extern void _FUNC(rewind)(FILE *); |
||
127 | |||
128 | extern void _FUNC(clearerr)(FILE *); |
||
129 | extern int _FUNC(feof)(FILE *); |
||
130 | extern int _FUNC(ferror)(FILE *); |
||
131 | extern void _FUNC(perror)(const char *); |
||
132 | |||
133 | extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict); |
||
134 | |||
135 | extern int _FUNC(getchar)(void); |
||
136 | |||
137 | #endif // _STDIO_H_><>><>><> |