From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/stdio/fputc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/libc/stdio/fputc.c (limited to 'lib/libc/stdio/fputc.c') diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c new file mode 100644 index 00000000..c544d5dd --- /dev/null +++ b/lib/libc/stdio/fputc.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int fputc(int c, FILE *stream) +{ + if (!stream) { + errno = EINVAL; + return EOF; + } + + // Special case for string buffer operations (snprintf) + // When fd is -1, we're writing to a string buffer + if (stream->fd == -1 && stream->buf != NULL) { + // Check if there's space (leave room for null terminator) + if (stream->buf_len >= stream->buf_size - 1) { + return EOF; + } + + stream->buf[stream->buf_len++] = (char)c; + return (unsigned char)c; + } + + // For regular file operations, use fwrite + return fwrite(&c, 1, 1, stream) ? c : EOF; +} -- cgit v1.2.3