summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorPetr Baudis <pasky@ucw.cz>2005-04-13 02:28:48 -0700
committerPetr Baudis <xpasky@machine>2005-04-13 02:28:48 -0700
commit2de381f919829aec1e35d6c7cc33519295dcd053 (patch)
tree3f703cd0cd32a4aa9892bda84c664c36e40f7921 /read-cache.c
parentbdd4da595a265a091a859754a22688f7351cddee (diff)
downloadgit-2de381f919829aec1e35d6c7cc33519295dcd053.tar.gz
[PATCH] Consolidate the error handling
Now there is error() for "library" errors and die() for fatal "application" errors. usage() is now used strictly only for usage errors. Signed-off-by: Petr Baudis <pasky@ucw.cz>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/read-cache.c b/read-cache.c
index f1abae1442..d8b383fe6b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,24 +3,47 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+#include <stdarg.h>
#include "cache.h"
const char *sha1_file_directory = NULL;
struct cache_entry **active_cache = NULL;
unsigned int active_nr = 0, active_alloc = 0;
-void usage(const char *err, ...)
+void usage(const char *err)
{
- va_list args;
- char string[200];
+ fprintf(stderr, "usage: %s\n", err);
+ exit(1);
+}
+
+static void report(const char *prefix, const char *err, va_list params)
+{
+ fputs(prefix, stderr);
+ vfprintf(stderr, err, params);
+ fputs("\n", stderr);
+}
- va_start(args, err);
- vsnprintf(string, sizeof(string), err, args);
- va_end(args);
- fprintf(stderr, "%s\n", string);
+void die(const char *err, ...)
+{
+ va_list params;
+
+ va_start(params, err);
+ report("fatal: ", err, params);
+ va_end(params);
exit(1);
}
+int error(const char *err, ...)
+{
+ va_list params;
+
+ va_start(params, err);
+ report("error: ", err, params);
+ va_end(params);
+ return -1;
+}
+
+
static unsigned hexval(char c)
{
if (c >= '0' && c <= '9')
@@ -218,7 +241,6 @@ int write_sha1_buffer(const unsigned char *sha1, void *buf, unsigned int size)
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0) {
void *map;
- static int error(const char * string);
if (errno != EEXIST)
return -1;
@@ -240,12 +262,6 @@ int write_sha1_buffer(const unsigned char *sha1, void *buf, unsigned int size)
return 0;
}
-static int error(const char * string)
-{
- fprintf(stderr, "error: %s\n", string);
- return -1;
-}
-
int cache_match_stat(struct cache_entry *ce, struct stat *st)
{
unsigned int changed = 0;