Skip to content

Commit

Permalink
Suppress errno from wait() and stat()
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhsnn committed Feb 23, 2024
1 parent ac9ddf4 commit 7b7c986
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ static void run_subprocess(char **argv) {

// Wait for the child process to finish.
int status;
while (wait(&status) > 0);
if (status != 0)
if (wait(&status) <= 0 || status != 0)
exit(1);
}

Expand Down Expand Up @@ -669,8 +668,13 @@ static char *find_file(char *pattern) {

// Returns true if a given file exists.
bool file_exists(char *path) {
assert(!errno);

struct stat st;
return !stat(path, &st);
bool found = !stat(path, &st);
if (!found && errno == ENOENT)
errno = 0;
return found;
}

static char *find_libpath(void) {
Expand Down
4 changes: 4 additions & 0 deletions preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,14 @@ static Token *counter_macro(Token *start) {
// modification time of the current file. E.g.
// "Fri Jul 24 01:32:50 2020"
static Token *timestamp_macro(Token *start) {
assert(!errno);

Token *tok;
struct stat st;
if (stat(start->file->name, &st) != 0) {
tok = new_str_token("??? ??? ?? ??:??:?? ????", start);
if (errno == ENOENT)
errno = 0;
} else {
char buf[30];
ctime_r(&st.st_mtime, buf);
Expand Down

0 comments on commit 7b7c986

Please sign in to comment.