diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:27:56 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-22 23:30:32 +0100 |
| commit | 0f30d227497418c6d3bef7d52244407e30454504 (patch) | |
| tree | 0e1ac19623d3268380cf74328cdf643648a2f43c /lib/libc/stdio/fputc.c | |
| parent | 90dad97fc07f049383903a166631e2c257f9b8c1 (diff) | |
Added c11 threads, fixed some locks and add *_unlocked functions
Diffstat (limited to 'lib/libc/stdio/fputc.c')
| -rw-r--r-- | lib/libc/stdio/fputc.c | 25 |
1 files changed, 6 insertions, 19 deletions
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 <errno.h> // for EINVAL, errno -#include <stdio.h> // for EOF, fwrite, FILE, fputc +#include <stdio.h> 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; } |
