diff options
author | Anton Kling <anton@kling.gg> | 2024-10-03 15:08:45 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-10-03 15:08:45 +0200 |
commit | 226d861c9ebb7f09f95665d07d9ab5c6b7ed7d6f (patch) | |
tree | d900c3437d3d65ee7bd88474586dc6dd947b14ce /userland/libc/stdio | |
parent | 64b0b49a1f23da9faa680f8158cb8a12cd4d118c (diff) |
libc: small changes
Diffstat (limited to 'userland/libc/stdio')
-rw-r--r-- | userland/libc/stdio/fclose.c | 6 | ||||
-rw-r--r-- | userland/libc/stdio/fopen.c | 1 | ||||
-rw-r--r-- | userland/libc/stdio/fwrite.c | 1 | ||||
-rw-r--r-- | userland/libc/stdio/vdprintf.c | 11 |
4 files changed, 16 insertions, 3 deletions
diff --git a/userland/libc/stdio/fclose.c b/userland/libc/stdio/fclose.c index 01bdb22..eb92387 100644 --- a/userland/libc/stdio/fclose.c +++ b/userland/libc/stdio/fclose.c @@ -4,8 +4,12 @@ // https://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html // FIXME: Do some actual error checking. int fclose(FILE *stream) { - if (stream) + if (stream) { + if (stream->fflush) { + stream->fflush(stream); + } free(stream->cookie); + } free(stream); return 0; } diff --git a/userland/libc/stdio/fopen.c b/userland/libc/stdio/fopen.c index 71d14db..52e78d1 100644 --- a/userland/libc/stdio/fopen.c +++ b/userland/libc/stdio/fopen.c @@ -56,5 +56,6 @@ FILE *fopen(const char *pathname, const char *mode) { r->fd = fd; r->read_buffer = NULL; r->read_buffer_stored = 0; + r->fflush = fflush_fd; return r; } diff --git a/userland/libc/stdio/fwrite.c b/userland/libc/stdio/fwrite.c index 6065465..6499529 100644 --- a/userland/libc/stdio/fwrite.c +++ b/userland/libc/stdio/fwrite.c @@ -8,5 +8,6 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { // On success, fwrite() return the number of items // written. rc /= size; + fflush(stream); return rc; } diff --git a/userland/libc/stdio/vdprintf.c b/userland/libc/stdio/vdprintf.c index 2724c2e..01727c4 100644 --- a/userland/libc/stdio/vdprintf.c +++ b/userland/libc/stdio/vdprintf.c @@ -1,9 +1,12 @@ #include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> -size_t min(size_t a, size_t b) { return (a < b) ? a : b; } +size_t min(size_t a, size_t b) { + return (a < b) ? a : b; +} int vdprintf(int fd, const char *format, va_list ap) { FILE f = { @@ -11,6 +14,10 @@ int vdprintf(int fd, const char *format, va_list ap) { .fd = fd, .fflush = fflush_fd, .write_buffer = NULL, + .read_buffer = NULL, }; - return vfprintf(&f, format, ap); + int rc = vfprintf(&f, format, ap); + free(f.write_buffer); + free(f.read_buffer); + return rc; } |