summaryrefslogtreecommitdiffstats
path: root/bin/sh/error.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-12-21 20:47:06 +0000
committerjilles <jilles@FreeBSD.org>2010-12-21 20:47:06 +0000
commiteb00352e45c46febb8e2b0df1a048451d79de792 (patch)
tree9100639c6e991583a424211610f1fda83edfd6a2 /bin/sh/error.c
parentda7284d25303e2c3a5c54e86ebdd14fd514eb5f9 (diff)
downloadFreeBSD-src-eb00352e45c46febb8e2b0df1a048451d79de792.zip
FreeBSD-src-eb00352e45c46febb8e2b0df1a048451d79de792.tar.gz
sh: Add a function to print warnings (with command name and newline).
This is like error() but without raising an exception. It is particularly useful as a replacement for the warnx macro in bltin/bltin.h.
Diffstat (limited to 'bin/sh/error.c')
-rw-r--r--bin/sh/error.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/bin/sh/error.c b/bin/sh/error.c
index beb75fa..c76a9dc 100644
--- a/bin/sh/error.c
+++ b/bin/sh/error.c
@@ -134,6 +134,26 @@ onint(void)
}
+static void
+vwarning(const char *msg, va_list ap)
+{
+ if (commandname)
+ outfmt(out2, "%s: ", commandname);
+ doformat(out2, msg, ap);
+ out2fmt_flush("\n");
+}
+
+
+void
+warning(const char *msg, ...)
+{
+ va_list ap;
+ va_start(ap, msg);
+ vwarning(msg, ap);
+ va_end(ap);
+}
+
+
/*
* Exverror is called to raise the error exception. If the first argument
* is not NULL then error prints an error message using printf style
@@ -158,12 +178,8 @@ exverror(int cond, const char *msg, va_list ap)
else
TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
#endif
- if (msg) {
- if (commandname)
- outfmt(out2, "%s: ", commandname);
- doformat(out2, msg, ap);
- out2c('\n');
- }
+ if (msg)
+ vwarning(msg, ap);
flushall();
exraise(cond);
}
OpenPOWER on IntegriCloud