ref: d08bcc455d372662ec687897ef46c1a3a299e5e9
parent: aaa92659ea2bb5d645392fa9c86fe82e020042b7
author: Jakub Kądziołka <[email protected]>
date: Tue Mar 30 19:24:15 EDT 2021
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.
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -473,6 +473,11 @@
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 */