diff options
author | H. Peter Anvin <hpa@zytor.com> | 2018-06-15 18:20:17 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2018-06-15 18:20:17 -0700 |
commit | c51369067ce7cfac43d8bc8681a3c916d8d5e503 (patch) | |
tree | 185bbd5df654b0e0c61c84aa2da144f18406e5f3 /nasmlib | |
parent | d3b1832c049c533656fd1945440d637f01a0f1a4 (diff) | |
download | nasm-c51369067ce7cfac43d8bc8681a3c916d8d5e503.tar.gz |
errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.
Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'nasmlib')
-rw-r--r-- | nasmlib/file.c | 10 | ||||
-rw-r--r-- | nasmlib/malloc.c | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/nasmlib/file.c b/nasmlib/file.c index c0b4e781..c7bd1a62 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -37,9 +37,9 @@ void nasm_read(void *ptr, size_t size, FILE *f) { size_t n = fread(ptr, 1, size, f); if (ferror(f)) { - nasm_fatal(0, "unable to read input: %s", strerror(errno)); + nasm_fatal("unable to read input: %s", strerror(errno)); } else if (n != size || feof(f)) { - nasm_fatal(0, "fatal short read on input"); + nasm_fatal("fatal short read on input"); } } @@ -47,7 +47,7 @@ void nasm_write(const void *ptr, size_t size, FILE *f) { size_t n = fwrite(ptr, 1, size, f); if (n != size || ferror(f) || feof(f)) - nasm_fatal(0, "unable to write output: %s", strerror(errno)); + nasm_fatal("unable to write output: %s", strerror(errno)); } void fwriteint16_t(uint16_t data, FILE * fp) @@ -119,7 +119,7 @@ FILE *nasm_open_read(const char *filename, enum file_flags flags) f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb"); if (!f && (flags & NF_FATAL)) - nasm_fatal(ERR_NOFILE, "unable to open input file: `%s': %s", + nasm_fatal_fl(ERR_NOFILE, "unable to open input file: `%s': %s", filename, strerror(errno)); return f; @@ -132,7 +132,7 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags) f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb"); if (!f && (flags & NF_FATAL)) - nasm_fatal(ERR_NOFILE, "unable to open output file: `%s': %s", + nasm_fatal_fl(ERR_NOFILE, "unable to open output file: `%s': %s", filename, strerror(errno)); return f; diff --git a/nasmlib/malloc.c b/nasmlib/malloc.c index ccbc0c75..1e643185 100644 --- a/nasmlib/malloc.c +++ b/nasmlib/malloc.c @@ -44,7 +44,7 @@ static no_return nasm_alloc_failed(void) { - nasm_fatal(0, "out of memory"); + nasm_fatal("out of memory"); } static inline void *validate_ptr(void *p) |