blob: d42fdd2728cd9b72b3683eaa8d0ae71e15cf380c [file] [log] [blame]
Masahiro Yamada5e882e92017-09-16 14:10:39 +09001#ifndef __STDIO_H
2#define __STDIO_H
3
4#include <stdarg.h>
5#include <linux/compiler.h>
6
7/* stdin */
Heinrich Schuchardtc4954fb2020-10-07 18:11:48 +02008int getchar(void);
Masahiro Yamada5e882e92017-09-16 14:10:39 +09009int tstc(void);
10
11/* stdout */
Simon Glass209ae762024-09-29 19:49:49 -060012#if !defined(CONFIG_XPL_BUILD) || CONFIG_IS_ENABLED(SERIAL)
Masahiro Yamada5e882e92017-09-16 14:10:39 +090013void putc(const char c);
14void puts(const char *s);
Pali Rohár5aceb262022-09-05 11:31:17 +020015#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
16void flush(void);
17#else
18static inline void flush(void) {}
19#endif
Masahiro Yamada5e882e92017-09-16 14:10:39 +090020int __printf(1, 2) printf(const char *fmt, ...);
21int vprintf(const char *fmt, va_list args);
22#else
23static inline void putc(const char c)
24{
25}
26
27static inline void puts(const char *s)
28{
29}
30
Pali Rohár5aceb262022-09-05 11:31:17 +020031static inline void flush(void)
32{
33}
34
Masahiro Yamada5e882e92017-09-16 14:10:39 +090035static inline int __printf(1, 2) printf(const char *fmt, ...)
36{
37 return 0;
38}
39
40static inline int vprintf(const char *fmt, va_list args)
41{
42 return 0;
43}
44#endif
45
Raymond Mao24da8312024-05-16 14:11:52 -070046/**
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 */
60int snprintf(char *buf, size_t size, const char *fmt, ...)
61 __attribute__ ((format (__printf__, 3, 4)));
62
Masahiro Yamada5e882e92017-09-16 14:10:39 +090063/*
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ár5aceb262022-09-05 11:31:17 +020074#define eflush() fflush(stderr)
Masahiro Yamada5e882e92017-09-16 14:10:39 +090075#define eprintf(fmt, args...) fprintf(stderr, fmt, ##args)
76
77int __printf(2, 3) fprintf(int file, const char *fmt, ...);
78void fputs(int file, const char *s);
79void fputc(int file, const char c);
Pali Rohár5aceb262022-09-05 11:31:17 +020080#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
81void fflush(int file);
82#else
83static inline void fflush(int file) {}
84#endif
Masahiro Yamada5e882e92017-09-16 14:10:39 +090085int ftstc(int file);
86int fgetc(int file);
87
88#endif /* __STDIO_H */