diff options
Diffstat (limited to 'lib/libk/stdio.h')
-rw-r--r-- | lib/libk/stdio.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/libk/stdio.h b/lib/libk/stdio.h new file mode 100644 index 0000000..5ef68f1 --- /dev/null +++ b/lib/libk/stdio.h @@ -0,0 +1,58 @@ +#pragma once + +#include <stdarg.h> + +///@defgroup libk libk +///@{ +///@defgroup stdio stdio +///@{ + +#ifdef __cplusplus +/** + * An object type used for streams + */ +struct kIoDevice { + /** Function that prints a character to the stream */ + virtual void putc(char) = 0; + /** Function that prints a string to the stream */ + virtual int puts(const char *, int) = 0; + /** Flush write buffers */ + virtual void flush() = 0; +}; +typedef kIoDevice FILE; +#else +typedef void FILE; +#endif + +/** A FILE value corresponding to stdin, the keyboard buffer */ +extern FILE *stdin; +/** A FILE value corresponding to stdout, the display */ +extern FILE *stdout; +/** A FILE value corresponding to stderr, the uart */ +extern FILE *stderr; + +#ifdef __cplusplus +extern "C" { +#endif +/** + * Write the formatted string to stdout + * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal) + * @return number of bytes written + */ +int printf(const char *restrict format, ...); + +/** + * Write the formatted string to stream; see printf + */ +int fprintf(FILE *restrict stream, const char *restrict format, ...); + +/** + * Write the formatted string to stream; see printf + */ +int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap); +#ifdef __cplusplus +} +#endif + +///@} +///@} |