Encapsulate fseek+ftell idiom in seekSize

This allows a single check for the return value of `seekSize`
to verify all three `fseek`+`ftell`+`fseek` calls.
This commit is contained in:
Rangi committed 2026-07-14 01:32:18 -04:00
1 parent e7855ea1b8
commit 7e2a3491a5
5 files changed
+34 -23

No files matched your search

+14
View File
@@ -25,6 +25,20 @@ int xclose(int fd) {
return close(fd);
}
long seekSize(FILE *file) {
if (fseek(file, 0, SEEK_END) != 0) {
return -1;
}
long size = ftell(file);
if (size < 0) {
return -1;
}
if (fseek(file, 0, SEEK_SET) != 0) {
return -1;
}
return size;
}
bool isNewline(int c) {
return c == '\r' || c == '\n';
}