summaryrefslogtreecommitdiff
path: root/src/stdio/fputc.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-12 16:32:02 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-12 16:32:02 -0400
commit5bd54dca15ac7a1d5b823d2eeb20779780424485 (patch)
tree9f54f20c88939785b0a65fea71c4ce7e1f1664d3 /src/stdio/fputc.c
parent556843458a3b38f1efe536fdb7ff3b0f65538e0f (diff)
handle locked/unlocked i/o better
Diffstat (limited to 'src/stdio/fputc.c')
-rw-r--r--src/stdio/fputc.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/stdio/fputc.c b/src/stdio/fputc.c
index 20cf5c6b..3123103b 100644
--- a/src/stdio/fputc.c
+++ b/src/stdio/fputc.c
@@ -1,32 +1,19 @@
#include <stdio.h>
#include "_stdio.h"
-#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE
-#include "sys/types.h"
-#include "unistd.h"
-#else
-#include "../_syscall.h"
-#define write(_fd, _buf, _size) __syscall(__syscall_lookup(write), _fd, _buf, _size)
+#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199506L
+#undef putc_unlocked
+#include "putc_unlocked.c"
#endif
/** write a character to a file stream **/
int fputc(int c, FILE *stream)
{
- unsigned char ch = (unsigned char)c;
+ int ret = EOF;
flockfile(stream);
-
- if (!stream) {
- return EOF;
- }
-
- if (write(stream->fd, &ch, sizeof(ch)) != 1) {
- /* error */
- return EOF;
- }
-
+ ret = putc_unlocked(c, stream);
funlockfile(stream);
-
- return ch;
+ return ret;
}
/***