From: Luke Dashjr <luke-jr+git@utopios.org>
To: git@vger.kernel.org
Cc: Luke Dashjr <luke-jr+git@utopios.org>
Subject: [PATCH 4/5] implement error_errno and warning_errno
Date: Wed, 12 Aug 2009 22:20:23 -0500 [thread overview]
Message-ID: <1250133624-2272-4-git-send-email-luke-jr+git@utopios.org> (raw)
In-Reply-To: <1250133624-2272-3-git-send-email-luke-jr+git@utopios.org>
This allows for easier conversion of code that currently does a (fatal)
die_errno to a safer error (which can be ignored), or perhaps even warning
status.
Signed-off-by: Luke Dashjr <luke-jr+git@utopios.org>
---
git-compat-util.h | 2 +
usage.c | 66 ++++++++++++++++++++++++-----------------------------
2 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 9f941e4..25d4c1e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -181,7 +181,9 @@ extern void usage(const char *err) NORETURN;
extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
diff --git a/usage.c b/usage.c
index b6aea45..dce90dc 100644
--- a/usage.c
+++ b/usage.c
@@ -39,7 +39,7 @@ static void warn_builtin(const char *warn, va_list params)
static void (*usage_routine)(const char *err) NORETURN = usage_builtin;
static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
static void (*error_routine)(const char *err, va_list params) = error_builtin;
-static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
+static void (*warning_routine)(const char *err, va_list params) = warn_builtin;
void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN)
{
@@ -51,19 +51,8 @@ void usage(const char *err)
usage_routine(err);
}
-void die(const char *err, ...)
+static void _e_errno(const char *fmt, char *fmt_with_err, size_t sizeof_fmt_with_err)
{
- va_list params;
-
- va_start(params, err);
- die_routine(err, params);
- va_end(params);
-}
-
-void die_errno(const char *fmt, ...)
-{
- va_list params;
- char fmt_with_err[1024];
char str_error[256], *err;
int i, j;
@@ -81,28 +70,33 @@ void die_errno(const char *fmt, ...)
}
}
str_error[j] = 0;
- snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
-
- va_start(params, fmt);
- die_routine(fmt_with_err, params);
- va_end(params);
-}
-
-int error(const char *err, ...)
-{
- va_list params;
-
- va_start(params, err);
- error_routine(err, params);
- va_end(params);
- return -1;
+ snprintf(fmt_with_err, sizeof_fmt_with_err, "%s: %s", fmt, str_error);
}
-void warning(const char *warn, ...)
-{
- va_list params;
-
- va_start(params, warn);
- warn_routine(warn, params);
- va_end(params);
-}
+#define BUILD_E(RTYPE, NAME, CODE) \
+RTYPE NAME(const char *err, ...) \
+{ \
+ va_list params; \
+ \
+ va_start(params, err); \
+ NAME ## _routine(err, params); \
+ va_end(params); \
+ CODE \
+} \
+ \
+RTYPE NAME ## _errno(const char *fmt, ...) \
+{ \
+ va_list params; \
+ static char fmt_with_err[1024]; \
+ \
+ va_start(params, fmt); \
+ _e_errno(fmt, fmt_with_err, sizeof(fmt_with_err)); \
+ NAME ## _routine(fmt_with_err, params); \
+ va_end(params); \
+ CODE \
+} \
+// END OF BUILD_E MACRO
+
+BUILD_E(void, die, )
+BUILD_E(int, error, return -1;)
+BUILD_E(void, warning, )
--
1.6.3.3
next prev parent reply other threads:[~2009-08-13 3:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-12 22:26 For review: git add --ignore-unmatch Luke-Jr
2009-08-12 22:57 ` Thomas Rast
2009-08-13 3:20 ` [PATCH 1/5] port --ignore-unmatch to "git add" Luke Dashjr
2009-08-13 3:20 ` [PATCH 2/5] fix "git add --ignore-errors" to ignore pathspec errors Luke Dashjr
2009-08-13 3:20 ` [PATCH 3/5] Document --ignore-unmatch in git-add.txt Luke Dashjr
2009-08-13 3:20 ` Luke Dashjr [this message]
2009-08-13 3:20 ` [PATCH 5/5] Convert add_file_to_index's lstat failure from a die to an error Luke Dashjr
2009-08-13 19:38 ` [PATCH 2/5] fix "git add --ignore-errors" to ignore pathspec errors Junio C Hamano
2009-08-13 20:42 ` Luke-Jr
2009-08-13 21:02 ` [PATCH] port --ignore-unmatch to "git add" Luke Dashjr
2009-08-13 21:03 ` [PATCH] Document --ignore-unmatch in git-add.txt Luke Dashjr
2009-08-13 19:36 ` [PATCH 1/5] port --ignore-unmatch to "git add" Junio C Hamano
2009-08-13 20:40 ` Luke-Jr
2009-08-13 21:51 ` Alex Riesen
2009-08-13 21:06 ` Thomas Rast
2009-08-14 19:52 ` Junio C Hamano
2009-08-14 20:39 ` Luke-Jr
2009-08-14 20:47 ` Luke-Jr
2009-08-14 21:39 ` Nanako Shiraishi
2009-08-14 22:54 ` Luke-Jr
2009-10-10 17:23 ` Luke-Jr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1250133624-2272-4-git-send-email-luke-jr+git@utopios.org \
--to=luke-jr+git@utopios.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).