scripting engine: better error handling in FileLoad

This commit is contained in:
nakst 2022-03-19 15:29:24 +00:00
parent f691a3a12d
commit 3e21e0bda3
1 changed files with 3 additions and 0 deletions

View File

@ -7882,6 +7882,9 @@ void *LibraryGetAddress(void *library, const char *name) {
void *FileLoad(const char *path, size_t *length) {
FILE *file = fopen(path, "rb");
if (!file) return NULL;
struct stat s;
fstat(fileno(file), &s);
if (!S_ISREG(s.st_mode)) { fclose(file); errno = EISDIR; return NULL; }
fseek(file, 0, SEEK_END);
size_t fileSize = ftell(file);
fseek(file, 0, SEEK_SET);