diff options
| author | Ray <[email protected]> | 2023-08-29 19:26:15 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-08-29 19:26:15 +0200 |
| commit | 8157d4283e5afc5e7822e5885aa7b27cd36ddf65 (patch) | |
| tree | 2b36d2584f28856452a727a22f2610fa79cc2b06 /src | |
| parent | 150663f78a1b4e656b20e954bd1ff42049559290 (diff) | |
| download | raylib-8157d4283e5afc5e7822e5885aa7b27cd36ddf65.tar.gz raylib-8157d4283e5afc5e7822e5885aa7b27cd36ddf65.zip | |
REVIEWED: `GetFileLength()`, added comment #3262
Diffstat (limited to 'src')
| -rw-r--r-- | src/rcore.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/rcore.c b/src/rcore.c index 210100fb..2c53eb5e 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -3192,13 +3192,24 @@ bool DirectoryExists(const char *dirPath) int GetFileLength(const char *fileName) { int size = 0; + + // NOTE: On Unix-like systems, it can by used the POSIX system call: stat(), + // but depending on the platform that call could not be available + //struct stat result = { 0 }; + //stat(fileName, &result); + //return result.st_size; FILE *file = fopen(fileName, "rb"); if (file != NULL) { fseek(file, 0L, SEEK_END); - size = (int)ftell(file); + long int fileSize = ftell(file); + + // Check for size overflow (INT_MAX) + if (fileSize > 2147483647) TRACELOG(LOG_WARNING, "[%s] File size overflows expected limit, do not use GetFileLength()", fileName); + else size = (int)fileSize; + fclose(file); } |
