diff options
| -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; |
