aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/read.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-10-11 21:12:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-10-11 21:12:54 +0000
commitf9e640f1c0dc5d4fbffde207f2a4b0350d1a0019 (patch)
treeab150c9d46fcd3c701e8245e2f3d5ccbab0db7be /read.c
parentede48977046b65029014a425213d622d938c74c4 (diff)
downloadmandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.tar.gz
mandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.tar.zst
mandoc-f9e640f1c0dc5d4fbffde207f2a4b0350d1a0019.zip
Finally use __progname, err(3) and warn(3).
That's more readable and less error-prone than fumbling around with argv[0], fprintf(3), strerror(3), perror(3), and exit(3). It's a bad idea to boycott good interfaces merely because standards committees ignore them. Instead, let's provide compatibility modules for archaic systems (like commercial Solaris) that still don't have them. The compat module has an UCB Copyright (c) 1993...
Diffstat (limited to 'read.c')
-rw-r--r--read.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/read.c b/read.c
index e15a813d..9af8ad4a 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.142 2015/10/06 18:32:19 schwarze Exp $ */
+/* $Id: read.c,v 1.143 2015/10/11 21:12:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -26,6 +26,7 @@
#include <assert.h>
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
@@ -612,10 +613,9 @@ read_whole_file(struct mparse *curp, const char *file, int fd,
#if HAVE_MMAP
struct stat st;
- if (-1 == fstat(fd, &st)) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+
+ if (fstat(fd, &st) == -1)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
/*
* If we're a regular file, try just reading in the whole entry
@@ -638,10 +638,8 @@ read_whole_file(struct mparse *curp, const char *file, int fd,
#endif
if (curp->gzip) {
- if ((gz = gzdopen(fd, "rb")) == NULL) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if ((gz = gzdopen(fd, "rb")) == NULL)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
} else
gz = NULL;
@@ -670,10 +668,8 @@ read_whole_file(struct mparse *curp, const char *file, int fd,
fb->sz = off;
return 1;
}
- if (ssz == -1) {
- perror(file);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ if (ssz == -1)
+ err((int)MANDOCLEVEL_SYSERR, "%s", file);
off += (size_t)ssz;
}