From f22689fcf5564bba6d925a799512f72a4665bee5 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 19 Jun 2023 10:48:02 +0200 Subject: [PATCH] libc: Add stubs for fflush() and ungetc() --- libc/include/stdio.h | 3 +++ libc/src/stdio.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 9be13eea..bab534d0 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -101,6 +101,9 @@ extern "C" /* Read a character from standard input. */ int getchar(void); + /* Push a character back to stream so that it can be read again. */ + int ungetc(int c, FILE* stream); + /* Read a line from stream. */ char* fgets(char* buf, size_t size, FILE* stream); diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index bdcd82e4..d58cae21 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -46,6 +46,12 @@ static int fdopen_check_compatible_mode(int fd, int new_flags) extern "C" { + int fflush(FILE*) + { + // FIXME: Files are not buffered right now. + return 0; + } + FILE* fopen(const char* path, const char* mode) { int flags; @@ -479,4 +485,9 @@ extern "C" if (!f) close(fd); return f; } + + int ungetc(int, FILE*) + { + fail("FIXME: ungetc: not implemented"); + } }