From d75de5f423aea018067486fd81a96a7abb70abc5 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 23 Oct 2022 11:12:54 +0200 Subject: [PATCH] libc: Partially implement ungetc --- libs/libc/src/file.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/libc/src/file.cpp b/libs/libc/src/file.cpp index 74507216..d8091b5a 100644 --- a/libs/libc/src/file.cpp +++ b/libs/libc/src/file.cpp @@ -170,9 +170,14 @@ extern "C" return fgetc(stdin); } - int ungetc(int, FILE*) + int ungetc(int c, FILE* stream) { - NOT_IMPLEMENTED("ungetc"); + if (stream->f_bufoff > 0) + { + stream->f_bufoff--; + stream->f_buf[stream->f_bufoff] = (char)c; + } + else { NOT_IMPLEMENTED("ungetc with buffer that has not been read"); } } int ferror(FILE* stream)