summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fputc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/fputc.c')
-rw-r--r--lib/libc/stdio/fputc.c25
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;
}