mirror of
https://github.com/gbdev/rgbds.git
synced 2026-11-22 13:48:39 +00:00
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:
1 parent
e7855ea1b8
commit
7e2a3491a5
5 files changed
+34
-23
No files matched your search
@@ -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';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user