diff options
| author | WormHeamer | 2025-12-02 05:18:30 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-12-02 05:18:30 -0500 |
| commit | 5b6ee7e762b7b6db2e4979d740a104d7b8dc15fd (patch) | |
| tree | 2f46d37913656d0b8cfe68e91ecc97e491c9eea9 | |
| parent | 7b85b8ae6162aace521fe1051c576f9889155350 (diff) | |
add fstat() implementation for read_all_file_size()
| -rw-r--r-- | strio.h | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -28,12 +28,21 @@ const char *cstr_fmt(Arena *arena, const char *fmt, ...); #include <stdint.h> #include <stdarg.h> +#if defined(__linux__) || defined(_POSIX_C_SOURCE) +#include <sys/stat.h> +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; |
