From 0f30d227497418c6d3bef7d52244407e30454504 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 22 Dec 2025 23:27:56 +0100 Subject: Added c11 threads, fixed some locks and add *_unlocked functions --- lib/libc/stdio/fputc.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'lib/libc/stdio/fputc.c') diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index 922011f2..365fbb96 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -1,25 +1,12 @@ -#include "stddef.h" // for NULL - -#include <__stdio.h> // for __FILE -#include // for EINVAL, errno -#include // for EOF, fwrite, FILE, fputc +#include int fputc(int c, FILE *stream) { - if (stream == NULL) { - errno = EINVAL; - return EOF; - } - - if ((__FILE(stream))->fd == -1 && (__FILE(stream))->buf != NULL) { - if ((__FILE(stream))->buf_len >= - (__FILE(stream))->buf_size - 1) { - return EOF; - } + int r; - (__FILE(stream))->buf[(__FILE(stream))->buf_len++] = (char)c; - return (unsigned char)c; - } + flockfile(stream); + r = fputc_unlocked(c, stream); + funlockfile(stream); - return fwrite(&c, 1, 1, stream) ? c : EOF; + return r; } -- cgit v1.2.3