summaryrefslogtreecommitdiff
path: root/nasmlib/file.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-06-15 18:20:17 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-06-15 18:20:17 -0700
commitc51369067ce7cfac43d8bc8681a3c916d8d5e503 (patch)
tree185bbd5df654b0e0c61c84aa2da144f18406e5f3 /nasmlib/file.c
parentd3b1832c049c533656fd1945440d637f01a0f1a4 (diff)
downloadnasm-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/file.c')
-rw-r--r--nasmlib/file.c10
1 files changed, 5 insertions, 5 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;