From 41ee6b43c89ce67808a684ba67f69e964b0636fa Mon Sep 17 00:00:00 2001 From: aqua Date: Sat, 18 Feb 2023 10:12:24 +0200 Subject: Move C stdlib to lib/libk --- lib/libk/stdio.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/libk/stdio.h (limited to 'lib/libk/stdio.h') 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 + +///@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 + +///@} +///@} -- cgit v1.2.1