commit 6df1301594433963840b29d6ae42fb6de4b056c8
parent f7a4849ded9292fce96bcd3afe7ff63c4834b763
Author: sin <sin@2f30.org>
Date: Wed, 12 Mar 2014 16:18:29 +0200
Add weprintf()
Diffstat:
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/util.h b/util.h
@@ -19,3 +19,4 @@ size_t strlcat(char *, const char *, size_t);
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
char *ttytostr(int, int);
+void weprintf(const char *, ...);
diff --git a/util/eprintf.c b/util/eprintf.c
@@ -44,3 +44,20 @@ venprintf(int status, const char *fmt, va_list ap)
exit(status);
}
+
+void
+weprintf(const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf(stderr, "%s: ", argv0);
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ }
+}