git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Stephan Beyer <s-beyer@gmx.net>,
	Daniel Barkalow <barkalow@iabervon.org>,
	Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [RFC/PATCH 03/18] usage: implement error_errno() the same way as die_errno()
Date: Thu, 25 Nov 2010 22:20:34 +0100	[thread overview]
Message-ID: <20101125212050.5188.56613.chriscool@tuxfamily.org> (raw)
In-Reply-To: <20101125210138.5188.13115.chriscool@tuxfamily.org>

die_errno() is very useful, but sometimes we don't want to
die after printing an error message and the error message
from errno. So let's implement error_errno() that does the
same thing as die_errno() except that it calls
error_routine() instead of die_routine().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-compat-util.h |    1 +
 usage.c           |   28 ++++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 490f969..32294cc 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -230,6 +230,7 @@ extern NORETURN void usage(const char *err);
 extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern int error_errno(const char *err, ...) __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 ec4cf53..f3ac869 100644
--- a/usage.c
+++ b/usage.c
@@ -69,10 +69,9 @@ void die(const char *err, ...)
 	va_end(params);
 }
 
-void die_errno(const char *fmt, ...)
+static void format_errno(char *fmt_with_err, size_t fmt_with_err_size,
+			 const char *fmt)
 {
-	va_list params;
-	char fmt_with_err[1024];
 	char str_error[256], *err;
 	int i, j;
 
@@ -90,13 +89,34 @@ void die_errno(const char *fmt, ...)
 		}
 	}
 	str_error[j] = 0;
-	snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
+	snprintf(fmt_with_err, fmt_with_err_size, "%s: %s", fmt, str_error);
+}
+
+void die_errno(const char *fmt, ...)
+{
+	va_list params;
+	char fmt_with_err[1024];
+
+	format_errno(fmt_with_err, sizeof(fmt_with_err), fmt);
 
 	va_start(params, fmt);
 	die_routine(fmt_with_err, params);
 	va_end(params);
 }
 
+int error_errno(const char *fmt, ...)
+{
+	va_list params;
+	char fmt_with_err[1024];
+
+	format_errno(fmt_with_err, sizeof(fmt_with_err), fmt);
+
+	va_start(params, fmt);
+	error_routine(fmt_with_err, params);
+	va_end(params);
+	return -1;
+}
+
 int error(const char *err, ...)
 {
 	va_list params;
-- 
1.7.3.2.504.g59d466

  parent reply	other threads:[~2010-11-26  5:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-25 21:20 [RFC/PATCH 00/18] WIP implement cherry-pick/revert --continue Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 01/18] advice: add error_resolve_conflict() function Christian Couder
2010-11-26  5:56   ` Jonathan Nieder
2010-11-25 21:20 ` [RFC/PATCH 02/18] revert: change many die() calls into "return error()" calls Christian Couder
2010-11-26  6:05   ` Jonathan Nieder
2010-11-25 21:20 ` Christian Couder [this message]
2010-11-26  6:07   ` [RFC/PATCH 03/18] usage: implement error_errno() the same way as die_errno() Jonathan Nieder
2010-11-26 18:35   ` Junio C Hamano
2010-11-25 21:20 ` [RFC/PATCH 04/18] revert: don't die when write_message() fails Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 05/18] commit: move reverse_commit_list() into commit.{h, c} Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 06/18] revert: remove "commit" global variable Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 07/18] revert: put option information in an option struct Christian Couder
2010-11-26  6:18   ` Jonathan Nieder
2010-11-26 18:42   ` Junio C Hamano
2010-11-25 21:20 ` [RFC/PATCH 08/18] revert: refactor code into a new pick_commits() function Christian Couder
2010-11-27  3:50   ` Daniel Barkalow
2010-11-25 21:20 ` [RFC/PATCH 09/18] revert: make pick_commits() return an error on --ff incompatible option Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 10/18] revert: make read_and_refresh_cache() and prepare_revs() return errors Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 11/18] revert: add get_todo_content() and create_todo_file() Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 12/18] revert: write TODO and DONE files in case of failure Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 13/18] revert: add option parsing for option --continue Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 14/18] revert: move global variable "me" into "struct args_info" Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 15/18] revert: add NONE action and make parse_args() manage it Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 16/18] revert: implement parsing TODO and DONE files Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 17/18] revert: add remaining instructions in todo file Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 18/18] revert: implement --continue processing Christian Couder
2010-11-26  6:28 ` [RFC/PATCH 00/18] WIP implement cherry-pick/revert --continue Jonathan Nieder

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=20101125212050.5188.56613.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=s-beyer@gmx.net \
    --cc=torvalds@linux-foundation.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).