git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] diesys calls die and also reports strerror(errno)

From
APAlexander 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
Previous: Jeff KingNext: Jeff King
Message 3 of 28 in “add strerror(errno) to die() calls where applicable”
  1. add strerror(errno) to die() calls where applicableThomas Rast, Jun 2, 2009
  2. Jeff KingJun 3, 2009
  3. diesys calls die and also reports strerror(errno)Alexander Potashev, Jun 4, 2009
  4. Jeff KingJun 4, 2009
  5. Junio C HamanoJun 4, 2009
  6. Johannes SixtJun 5, 2009
  7. Junio C HamanoJun 5, 2009
  8. Jeff KingJun 6, 2009
  9. Thomas RastJun 6, 2009
  10. 0/3 Thomas Rast <trast@student.ethz.ch>Thomas Rast, Jun 6, 2009
  11. 1/3 Introduce die_errno() that appends strerror(errno) to die()Thomas Rast, Jun 6, 2009
  12. 2/3 Convert existing die(..., strerror(errno)) to die_errno()Thomas Rast, Jun 6, 2009
  13. 3/3 Use die_errno() instead of die() when checking syscallsThomas Rast, Jun 6, 2009
  14. Johannes SixtJun 6, 2009
  15. Thomas RastJun 6, 2009
  16. Johannes SixtJun 6, 2009
  17. Johannes SixtJun 6, 2009
  18. Thomas RastJun 6, 2009
  19. Johannes SixtJun 6, 2009
  20. Jeff KingJun 6, 2009
  21. Jeff KingJun 6, 2009
  22. Alexander PotashevJun 7, 2009
  23. Junio C HamanoJun 7, 2009
  24. Jeff KingJun 8, 2009
  25. Alexander PotashevJun 8, 2009
  26. Jeff KingJun 8, 2009
  27. Alexander PotashevJun 4, 2009
  28. Jeff KingJun 4, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.