diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-15 21:33:22 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-15 21:33:22 -0400 |
commit | 7cdee943fc3bef1912f9f0547e7b5d8049c98599 (patch) | |
tree | 83562f969f27b4be602a89061285957e12b20147 /src/stdio/fflush.c | |
parent | 3448597bff1103d603a611f5df29ce5a91466126 (diff) |
actually flush output
Diffstat (limited to 'src/stdio/fflush.c')
-rw-r--r-- | src/stdio/fflush.c | 34 |
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; } /*** |