Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 1 | #ifndef __STDIO_H |
| 2 | #define __STDIO_H |
| 3 | |
| 4 | #include <stdarg.h> |
| 5 | #include <linux/compiler.h> |
| 6 | |
| 7 | /* stdin */ |
Heinrich Schuchardt | c4954fb | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 8 | int getchar(void); |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 9 | int tstc(void); |
| 10 | |
| 11 | /* stdout */ |
Simon Glass | 209ae76 | 2024-09-29 19:49:49 -0600 | [diff] [blame] | 12 | #if !defined(CONFIG_XPL_BUILD) || CONFIG_IS_ENABLED(SERIAL) |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 13 | void putc(const char c); |
| 14 | void puts(const char *s); |
Pali Rohár | 5aceb26 | 2022-09-05 11:31:17 +0200 | [diff] [blame] | 15 | #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT |
| 16 | void flush(void); |
| 17 | #else |
| 18 | static inline void flush(void) {} |
| 19 | #endif |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 20 | int __printf(1, 2) printf(const char *fmt, ...); |
| 21 | int vprintf(const char *fmt, va_list args); |
| 22 | #else |
| 23 | static inline void putc(const char c) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | static inline void puts(const char *s) |
| 28 | { |
| 29 | } |
| 30 | |
Pali Rohár | 5aceb26 | 2022-09-05 11:31:17 +0200 | [diff] [blame] | 31 | static inline void flush(void) |
| 32 | { |
| 33 | } |
| 34 | |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 35 | static inline int __printf(1, 2) printf(const char *fmt, ...) |
| 36 | { |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static inline int vprintf(const char *fmt, va_list args) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | #endif |
| 45 | |
Raymond Mao | 24da831 | 2024-05-16 14:11:52 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Format a string and place it in a buffer |
| 48 | * |
| 49 | * @buf: The buffer to place the result into |
| 50 | * @size: The size of the buffer, including the trailing null space |
| 51 | * @fmt: The format string to use |
| 52 | * @...: Arguments for the format string |
| 53 | * Return: the number of characters which would be |
| 54 | * generated for the given input, excluding the trailing null, |
| 55 | * as per ISO C99. If the return is greater than or equal to |
| 56 | * @size, the resulting string is truncated. |
| 57 | * |
| 58 | * See the vsprintf() documentation for format string extensions over C99. |
| 59 | */ |
| 60 | int snprintf(char *buf, size_t size, const char *fmt, ...) |
| 61 | __attribute__ ((format (__printf__, 3, 4))); |
| 62 | |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 63 | /* |
| 64 | * FILE based functions (can only be used AFTER relocation!) |
| 65 | */ |
| 66 | #define stdin 0 |
| 67 | #define stdout 1 |
| 68 | #define stderr 2 |
| 69 | #define MAX_FILES 3 |
| 70 | |
| 71 | /* stderr */ |
| 72 | #define eputc(c) fputc(stderr, c) |
| 73 | #define eputs(s) fputs(stderr, s) |
Pali Rohár | 5aceb26 | 2022-09-05 11:31:17 +0200 | [diff] [blame] | 74 | #define eflush() fflush(stderr) |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 75 | #define eprintf(fmt, args...) fprintf(stderr, fmt, ##args) |
| 76 | |
| 77 | int __printf(2, 3) fprintf(int file, const char *fmt, ...); |
| 78 | void fputs(int file, const char *s); |
| 79 | void fputc(int file, const char c); |
Pali Rohár | 5aceb26 | 2022-09-05 11:31:17 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT |
| 81 | void fflush(int file); |
| 82 | #else |
| 83 | static inline void fflush(int file) {} |
| 84 | #endif |
Masahiro Yamada | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 85 | int ftstc(int file); |
| 86 | int fgetc(int file); |
| 87 | |
| 88 | #endif /* __STDIO_H */ |