aboutsummaryrefslogtreecommitdiff
path: root/lib/libk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libk')
-rw-r--r--lib/libk/stdio.h35
-rw-r--r--lib/libk/stdio/vfprintf.c (renamed from lib/libk/stdio/vfprintf.cpp)18
2 files changed, 22 insertions, 31 deletions
diff --git a/lib/libk/stdio.h b/lib/libk/stdio.h
index 5ef68f1..b28eb5e 100644
--- a/lib/libk/stdio.h
+++ b/lib/libk/stdio.h
@@ -7,22 +7,19 @@
///@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
+/// An object type used for streams
+typedef struct FILE {
+ int id;
+
+ /// Function that prints a character to the stream
+ void (*putc)(const struct FILE *, char);
+
+ /// Function that prints a string to the stream
+ int (*puts)(const struct FILE *, const char *, int);
+
+ /// Flush write buffers
+ void (*flush)(const struct FILE *);
+} FILE;
/** A FILE value corresponding to stdin, the keyboard buffer */
extern FILE *stdin;
@@ -31,9 +28,6 @@ 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)
@@ -50,9 +44,6 @@ 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
///@}
///@}
diff --git a/lib/libk/stdio/vfprintf.cpp b/lib/libk/stdio/vfprintf.c
index aa9256d..d24e43e 100644
--- a/lib/libk/stdio/vfprintf.cpp
+++ b/lib/libk/stdio/vfprintf.c
@@ -3,7 +3,7 @@
static char buffer[3 * sizeof(int) + 2];
-extern "C" int
+int
vfprintf(FILE *restrict stream, const char *restrict format, va_list params)
{
int written = 0;
@@ -12,31 +12,31 @@ vfprintf(FILE *restrict stream, const char *restrict format, va_list params)
int l = 0;
for (int i = 0; format[i] != '\0'; ++i) {
if (format[i] == '%') {
- written += stream->puts(&format[s], l);
+ written += stream->puts(stream, &format[s], l);
s = i + 2;
++i;
switch (format[i]) {
case 's': {
const char *arg = va_arg(params, const char *);
- written += stream->puts(arg, -1);
+ written += stream->puts(stream, arg, -1);
} break;
case 'c': {
const int arg = va_arg(params, int);
- stream->putc(arg);
+ stream->putc(stream, arg);
++written;
} break;
case 'd': {
const char *arg = itoa(buffer, va_arg(params, int), 10);
- written += stream->puts(arg, -1);
+ written += stream->puts(stream, arg, -1);
} break;
case 'u': {
const char *arg = utoa(buffer, va_arg(params, unsigned int), 10);
- written += stream->puts(arg, -1);
+ written += stream->puts(stream, arg, -1);
} break;
case 'x': {
const char *arg = utoa(buffer, va_arg(params, unsigned int), 16);
- written += stream->puts(arg, -1);
+ written += stream->puts(stream, arg, -1);
} break;
}
@@ -47,8 +47,8 @@ vfprintf(FILE *restrict stream, const char *restrict format, va_list params)
++l;
}
- if (l > 0) { written += stream->puts(&format[s], l); }
+ if (l > 0) { written += stream->puts(stream, &format[s], l); }
- stream->flush();
+ stream->flush(stream);
return written;
}