From 5b6ee7e762b7b6db2e4979d740a104d7b8dc15fd Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Tue, 2 Dec 2025 05:18:30 -0500 Subject: add fstat() implementation for read_all_file_size() --- strio.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/strio.h b/strio.h index a99f8c3..a7df9ca 100644 --- a/strio.h +++ b/strio.h @@ -28,12 +28,21 @@ const char *cstr_fmt(Arena *arena, const char *fmt, ...); #include #include +#if defined(__linux__) || defined(_POSIX_C_SOURCE) +#include +static inline long read_all_file_size(FILE *f) { + struct stat b; + if (fstat(fileno(f), &b)) return -1; + return b.st_size; +} +#else static inline long read_all_file_size(FILE *f) { fseek(f, 0, SEEK_END); long t = ftell(f); fseek(f, 0, SEEK_SET); return t > 0 ? t : -1; } +#endif int read_all(FILE *f, Str *buf, Arena *a) { if (!f) return -1; -- cgit v1.2.3