From f704739a7cd8785688f096a55f1ad40142ecdede Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 22 Jul 2023 11:34:05 +0200 Subject: [PATCH] libc: Implement setbuf(), setbuffer(), and setlinebuf() These are all simple wrappers around setvbuf(). --- libc/include/stdio.h | 9 +++++++++ libc/src/stdio.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index f8f6961d..06fbd4b9 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -191,6 +191,15 @@ extern "C" /* Change a file's buffering mode and internal buffer. */ int setvbuf(FILE* stream, char* buf, int mode, size_t size); + /* Change a file's internal buffer. */ + void setbuf(FILE* stream, char* buf); + + /* Change a file's internal buffer. */ + void setbuffer(FILE* stream, char* buf, size_t size); + + /* Change a file's buffering mode to line buffered. */ + void setlinebuf(FILE* stream); + #ifdef __cplusplus } #endif diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index 6e84e267..e48e2900 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -729,4 +729,19 @@ extern "C" return 0; } + + void setbuf(FILE* stream, char* buf) + { + setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); + } + + void setbuffer(FILE* stream, char* buf, size_t size) + { + setvbuf(stream, buf, buf ? _IOFBF : _IONBF, size); + } + + void setlinebuf(FILE* stream) + { + setvbuf(stream, NULL, _IOLBF, 0); + } }