summaryrefslogtreecommitdiffstats
path: root/read.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-01-11 17:04:44 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-01-11 17:04:44 +0000
commit350e158d591d60167745a0943344c02f339a89a1 (patch)
treed21457782b2ae7e327147f2a4bfe68ef8e2bea7e /read.c
parent3be1a948007b770862e4e6b4bd927cc241a0d209 (diff)
downloadmandoc-350e158d591d60167745a0943344c02f339a89a1.tar.gz
Improve error reporting when a file given on the command line
cannot be opened: * Mention the filename. * Report the errno for the file itself, not the one with .gz appended.
Diffstat (limited to 'read.c')
-rw-r--r--read.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/read.c b/read.c
index 22c502c6..14f9a74e 100644
--- a/read.c
+++ b/read.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -607,7 +607,7 @@ int
mparse_open(struct mparse *curp, const char *file)
{
char *cp;
- int fd;
+ int fd, save_errno;
cp = strrchr(file, '.');
curp->gzip = (cp != NULL && ! strcmp(cp + 1, "gz"));
@@ -623,9 +623,11 @@ mparse_open(struct mparse *curp, const char *file)
*/
if ( ! curp->gzip) {
+ save_errno = errno;
mandoc_asprintf(&cp, "%s.gz", file);
fd = open(cp, O_RDONLY);
free(cp);
+ errno = save_errno;
if (fd != -1) {
curp->gzip = 1;
return fd;