Signed-off-by: Alexander Potashev <aspotashev@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html