source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Improve error reporting when a file given on the command line
@ 2019-01-11 17:05 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-01-11 17:05 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mandoc:
        main.c
        read.c

Revision Data
-------------
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.210
retrieving revision 1.211
diff -Lread.c -Lread.c -u -p -r1.210 -r1.211
--- read.c
+++ 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 c
 	 */
 
 	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;
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.317
retrieving revision 1.318
diff -Lmain.c -Lmain.c -u -p -r1.317 -r1.318
--- main.c
+++ main.c
@@ -561,7 +561,7 @@ main(int argc, char *argv[])
 			}
 		} else
 			mandoc_msg(MANDOCERR_FILE, 0, 0,
-			    "%s", strerror(errno));
+			    "%s: %s", thisarg, strerror(errno));
 
 		if (curp.wstop && mandoc_msg_getrc() != MANDOCLEVEL_OK)
 			break;
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-11 17:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 17:05 mandoc: Improve error reporting when a file given on the command line schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).