From 40b078e0a21ecb998702b895d80550ffb698414e Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 6 Nov 2022 14:46:22 +0100 Subject: [PATCH] libc: Make fread/fwrite return the number of items read/written instead of the number of bytes --- libs/libc/src/file.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/libc/src/file.cpp b/libs/libc/src/file.cpp index 147a82e0..d6836ed3 100644 --- a/libs/libc/src/file.cpp +++ b/libs/libc/src/file.cpp @@ -136,7 +136,7 @@ extern "C" return 0; } if (status == 0) stream->f_eof = 1; - return (size_t)status; + return (size_t)status / size; } char* fgets(char* buf, int size, FILE* stream) @@ -257,9 +257,7 @@ extern "C" long ftell(FILE* stream) { - return lseek(stream->f_fd, 0, - SEEK_CUR); // FIXME: Store the last seeked position in the file struct to avoid redundant syscalls - // maybe? We'd have to update this value in fread() and fwrite() as well... + return lseek(stream->f_fd, 0, SEEK_CUR); } off_t ftello(FILE* stream) @@ -290,7 +288,7 @@ extern "C" return 0; } if (status == 0) stream->f_eof = 1; - return (size_t)status; + return (size_t)status / size; } void setbuf(FILE*, char*)