Module Name: src Committed By: christos Date: Tue Mar 26 15:00:34 UTC 2019
Modified Files: src/usr.bin/m4: main.c Log Message: Behave like gnu m4; when the error output file cannot be opened, just warn and keep going. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/usr.bin/m4/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/m4/main.c diff -u src/usr.bin/m4/main.c:1.46 src/usr.bin/m4/main.c:1.47 --- src/usr.bin/m4/main.c:1.46 Sat Jan 23 09:24:43 2016 +++ src/usr.bin/m4/main.c Tue Mar 26 11:00:34 2019 @@ -1,5 +1,5 @@ /* $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */ -/* $NetBSD: main.c,v 1.46 2016/01/23 14:24:43 christos Exp $ */ +/* $NetBSD: main.c,v 1.47 2019/03/26 15:00:34 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -42,7 +42,7 @@ #include "nbtool_config.h" #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: main.c,v 1.46 2016/01/23 14:24:43 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.47 2019/03/26 15:00:34 christos Exp $"); #include <assert.h> #include <signal.h> #include <getopt.h> @@ -228,6 +228,7 @@ main(int argc, char *argv[]) int c; int n; char *p; + FILE *sfp; setprogname(argv[0]); @@ -263,9 +264,16 @@ main(int argc, char *argv[]) fatal_warnings++; break; case 'e': - if (freopen(optarg, "w+", stderr) == NULL) - err(EXIT_FAILURE, "Can't redirect errors to `%s'", - optarg); + /* + * Don't use freopen here because if it fails + * we lose stderr, instead trash it. + */ + if ((sfp = fopen(optarg, "w+")) == NULL) { + warn("Can't redirect errors to `%s'", optarg); + break; + } + fclose(stderr); + memcpy(stderr, sfp, sizeof(*sfp)); break; case 'F': freeze = optarg;