From 3e63da180bc6cbce7c0673419a1a4a0f021591bb Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 30 Jul 2021 15:03:21 -0700 Subject: Cleaner checking of stdlib negative returns --- files.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'files.c') diff --git a/files.c b/files.c index 202c88d..223079b 100644 --- a/files.c +++ b/files.c @@ -118,10 +118,8 @@ file_t *load_file(file_t **files, const char *filename) } finished_loading: - if (fd != STDIN_FILENO) { - if (close(fd) != 0) - err(EXIT_FAILURE, "Failed to close file"); - } + if (fd != STDIN_FILENO) + check_nonnegative(close(fd), "Failed to close file"); f->start = &f->memory[0]; f->end = &f->memory[length]; populate_lines(f, length); @@ -179,8 +177,8 @@ void destroy_file(file_t **f) if ((*f)->memory) { if ((*f)->mmapped) { - if (munmap((*f)->memory, (size_t)((*f)->end - (*f)->memory)) != 0) - err(EXIT_FAILURE, "Failure to un-memory-map some memory"); + check_nonnegative(munmap((*f)->memory, (size_t)((*f)->end - (*f)->memory)), + "Failure to un-memory-map some memory"); (*f)->memory = NULL; } else { xfree(&((*f)->memory)); -- cgit v1.2.3