[PATCH] diesys calls die and also reports strerror(errno)
- From
- Alexander Potashev <aspotashev@gmail.com>
- Date
- Jun 4, 2009, 02:05 UTC
- Message-ID
- <1244081105-7149-1-git-send-email-aspotashev@gmail.com>
- In-Reply-To
- <20090603015503.GA14166@coredump.intra.peff.net>
Signed-off-by: Alexander Potashev <aspotashev@gmail.com> --- Firstly I was going to write a 'adapt_to_fmt' function which would double all inclusions of '%', and then use it for strerror(err) and make printf-like functions happy (actually 'die_routine').
BUT, Have you ever seen an error description containing '%'? I haven't. So, handling the case of '%'s is not worth injecting several dump lines into the sources of the Beatiful Content Tracker.
git-compat-util.h | 1 + usage.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h index f25f7f1..cbfee60 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -162,6 +162,7 @@ extern char *gitbasename(char *); /* General helper functions */ extern void usage(const char *err) NORETURN; extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +extern void diesys(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); diff --git a/usage.c b/usage.c index 820d09f..e20f696 100644 --- a/usage.c +++ b/usage.c @@ -60,6 +60,24 @@ void die(const char *err, ...) va_end(params); } +void diesys(const char *err, ...) +{ + va_list params; + char *fullfmt; + const char *strerr; + + va_start(params, err); + + strerr = strerror(errno); + if (strchr(strerr, '%')) + strerr = "<error description contains '%%'>"; + fullfmt = xmalloc(strlen(err) + strlen(strerr) + 3); + sprintf(fullfmt, "%s: %s", err, strerr); + die_routine(fullfmt, params); + + va_end(params); +} + int error(const char *err, ...) { va_list params;
-- 1.6.2.3