diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-07-30 15:03:21 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-07-30 15:03:21 -0700 |
| commit | 3e63da180bc6cbce7c0673419a1a4a0f021591bb (patch) | |
| tree | 2e0a048c193eb7faf0bb0aff32b0181cb3efc6f5 /files.c | |
| parent | 33a63bb8d9e56424140d4b546bad5d10a3da97aa (diff) | |
Cleaner checking of stdlib negative returns
Diffstat (limited to 'files.c')
| -rw-r--r-- | files.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -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)); |
