Skip to content

Commit

Permalink
REVIEWED: GetFileLength(), added comment #3262
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Aug 29, 2023
1 parent 150663f commit 8157d42
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 8157d42

Please sign in to comment.