diff --git a/bin/sh/alias.c b/bin/sh/alias.c index c815b9289a32..0b7e31a2dbb1 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -246,7 +246,7 @@ aliascmd(int argc, char **argv) while ((n = *++argv) != NULL) { if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */ if ((ap = lookupalias(n, 0)) == NULL) { - outfmt(out2, "alias: %s not found\n", n); + warning("%s not found", n); ret = 1; } else printalias(ap); diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h index 6618108d350f..f6e788365aad 100644 --- a/bin/sh/bltin/bltin.h +++ b/bin/sh/bltin/bltin.h @@ -57,11 +57,7 @@ #define fwrite(ptr, size, nmemb, file) outbin(ptr, (size) * (nmemb), file) #define fflush flushout #define INITARGS(argv) -#define warnx(...) do { \ - out2fmt_flush("%s: ", commandname); \ - out2fmt_flush(__VA_ARGS__); \ - out2fmt_flush("\n"); \ - } while (0) +#define warnx warning #define errx(exitstatus, ...) error(__VA_ARGS__) #else diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 068dfb74209f..041d6b4545c3 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -224,7 +224,7 @@ cdphysical(char *dest) } p = findcwd(NULL); if (p == NULL) - out2fmt_flush("cd: warning: failed to get name of current directory\n"); + warning("warning: failed to get name of current directory"); updatepwd(p); INTON; return (0); diff --git a/bin/sh/error.c b/bin/sh/error.c index beb75fad2d8f..c76a9dc65768 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); } diff --git a/bin/sh/error.h b/bin/sh/error.h index 8b64fe6813d8..bf11c6750812 100644 --- a/bin/sh/error.h +++ b/bin/sh/error.h @@ -80,6 +80,7 @@ extern volatile sig_atomic_t intpending; void exraise(int) __dead2; void onint(void); +void warning(const char *, ...) __printflike(1, 2); void error(const char *, ...) __printf0like(1, 2) __dead2; void exerror(int, const char *, ...) __printf0like(2, 3) __dead2; diff --git a/bin/sh/trap.c b/bin/sh/trap.c index 3a6803b9d90f..e673ef685a3d 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -185,7 +185,7 @@ trapcmd(int argc, char **argv) } while (*argv) { if ((signo = sigstring_to_signum(*argv)) == -1) { - out2fmt_flush("trap: bad signal %s\n", *argv); + warning("bad signal %s", *argv); errors = 1; } INTOFF;