Skip to content

Commit

Permalink
fs_open fails if you try to open a directory;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Nov 23, 2023
1 parent d949b90 commit 1ef562d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ bool fs_open(const char* path, char mode, fs_handle* file) {
case 'a': flags = O_APPEND | O_WRONLY | O_CREAT; break;
default: return false;
}
struct stat stats;
file->fd = open(path, flags, S_IRUSR | S_IWUSR);
return file->fd >= 0;
return file->fd >= 0 && !fstat(file->fd, &stats) && !S_ISDIR(stats.st_mode);
}

bool fs_close(fs_handle file) {
Expand Down

0 comments on commit 1ef562d

Please sign in to comment.