844 m4 should say something useful about why an include()d file can't be opened
Reviewed by: Richard Lowe <
[email protected]>
Reviewed by: Garrett D'Amore <
[email protected]>
Approved by: Garrett D'Amore <
[email protected]>
--- a/usr/src/cmd/sgs/m4/common/m4.c Wed Apr 27 02:07:11 2011 +0000
+++ b/usr/src/cmd/sgs/m4/common/m4.c Fri May 06 07:32:53 2011 -0700
@@ -23,6 +23,10 @@
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
*/
+/*
+ * Copyright (c) 2011 Gary Mills
+ */
+
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
@@ -805,7 +809,8 @@
FILE *fp;
if ((fp = fopen(name, mode)) == NULL)
- error(gettext("can't open file"));
+ errorf(gettext("cannot open file: %s"),
+ strerror(errno));
return (fp);
}
@@ -865,6 +870,17 @@
return (ptr);
}
+/* Typical format: "cannot open file: %s" */
+/* PRINTFLIKE1 */
+void
+errorf(char *str, char *serr)
+{
+ char buf[500];
+
+ (void) snprintf(buf, sizeof (buf), str, serr);
+ error(buf);
+}
+
/* PRINTFLIKE1 */
void
error2(char *str, int num)
--- a/usr/src/cmd/sgs/m4/common/m4.h Wed Apr 27 02:07:11 2011 +0000
+++ b/usr/src/cmd/sgs/m4/common/m4.h Fri May 06 07:32:53 2011 -0700
@@ -26,6 +26,10 @@
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
*/
+/*
+ * Copyright (c) 2011 Gary Mills
+ */
+
#ifndef _M4_H
#define _M4_H
@@ -33,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <locale.h>
#include <limits.h>
@@ -161,6 +166,7 @@
extern int min(int, int);
extern void putbak(wchar_t);
extern void stkchr(wchar_t);
+extern void errorf(char *, char *);
extern void error2(char *, int);
extern wchar_t *wstrdup(wchar_t *);
--- a/usr/src/cmd/sgs/m4/common/m4macs.c Wed Apr 27 02:07:11 2011 +0000
+++ b/usr/src/cmd/sgs/m4/common/m4macs.c Fri May 06 07:32:53 2011 -0700
@@ -24,11 +24,13 @@
* Use is subject to license terms.
*/
+/*
+ * Copyright (c) 2011 Gary Mills
+ */
+
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
@@ -297,8 +299,8 @@
if ((ifile[++ifx] = fopen(wstr2str(ap[1], 0), "r")) == NULL) {
--ifx;
if (noisy)
- error(gettext(
- "can't open file"));
+ errorf(gettext("cannot open file: %s"),
+ strerror(errno));
} else {
ipstk[ifx] = ipflr = ip;
setfname(wstr2str(ap[1], 0));