summaryrefslogtreecommitdiff
path: root/src/stdio/fflush.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-15 21:33:22 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-15 21:33:22 -0400
commit7cdee943fc3bef1912f9f0547e7b5d8049c98599 (patch)
tree83562f969f27b4be602a89061285957e12b20147 /src/stdio/fflush.c
parent3448597bff1103d603a611f5df29ce5a91466126 (diff)
actually flush output
Diffstat (limited to 'src/stdio/fflush.c')
-rw-r--r--src/stdio/fflush.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index 1b70d8b0..a61f5323 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -1,30 +1,44 @@
#include <stdio.h>
#include "_stdio.h"
+#ifdef _POSIX_SOURCE
+#include <sys/types.h>
+#include <unistd.h>
+#else
+#include "_syscall.h"
+#define write(_fd, _buf, _size) __syscall(__syscall_lookup(write), _fd, _buf, _size)
+#endif
+
/** flush buffered writes **/
+
int fflush(FILE *stream)
{
- flockfile(stream);
+ int ret = 0;
+
if (stream == NULL) {
- FILE *p;
- for (p = __stdio.FILES; p != NULL; p = p->prev) {
- fflush(p);
+ size_t i;
+ for (i = 0; i < FOPEN_MAX; i++) {
+ fflush(&(__stdio.FILES[i]));
}
+ return 0;
}
- /*
- if (fsync(stream->fd) != 0) {
+ flockfile(stream);
+ if (write(stream->fd, stream->buf, stream->bpos) == -1) {
+ /* errno is set */
+ ret = EOF;
stream->err = 1;
- return EOF;
+ } else {
+ stream->bpos = 0;
}
- */
-
funlockfile(stream);
+
/*
RETURN_SUCCESS(0);
RETURN_FAILURE(CONSTANT(EOF));
*/
- return 0;
+
+ return ret;
}
/***