mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Handle errors when opening source file
Before this commit, opening a file for which the user didn't have permission resulted in a "Bad file descriptor" error.
This commit is contained in:
committed by
Eldred Habert
parent
aaa92659ea
commit
d08bcc455d
@@ -473,6 +473,11 @@ struct LexerState *lexer_OpenFile(char const *path)
|
||||
state->path = path;
|
||||
state->isFile = true;
|
||||
state->fd = isStdin ? STDIN_FILENO : open(path, O_RDONLY);
|
||||
if (state->fd < 0) {
|
||||
error("Failed to open file \"%s\": %s\n", path, strerror(errno));
|
||||
free(state);
|
||||
return NULL;
|
||||
}
|
||||
state->isMmapped = false; /* By default, assume it won't be mmap()ed */
|
||||
if (!isStdin && fileInfo.st_size > 0) {
|
||||
/* Try using `mmap` for better performance */
|
||||
|
||||
Reference in New Issue
Block a user