summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-03-09 19:55:50 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-09 20:09:22 +0100
commitdda708e78f3c3f43d814d46c29ab9f2b9d47ed5c (patch)
tree60a6e01583c15209a42740a46e182ac7cbc893de /src/util.h
parent6af24ce31f43c3621f11720704a078058665bc3f (diff)
downloadlibgit2-dda708e78f3c3f43d814d46c29ab9f2b9d47ed5c.tar.gz
error-handling: On-disk config file backend
Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller!
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/util.h b/src/util.h
index 01755b59e..afa3f7205 100644
--- a/src/util.h
+++ b/src/util.h
@@ -7,8 +7,6 @@
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
-#include "git2/errors.h"
-
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
@@ -24,24 +22,21 @@
GIT_INLINE(void *) git__malloc(size_t len)
{
void *ptr = malloc(len);
- if (!ptr)
- giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)len);
+ if (!ptr) giterr_set_oom();
return ptr;
}
GIT_INLINE(void *) git__calloc(size_t nelem, size_t elsize)
{
void *ptr = calloc(nelem, elsize);
- if (!ptr)
- giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)nelem*elsize);
+ if (!ptr) giterr_set_oom();
return ptr;
}
GIT_INLINE(char *) git__strdup(const char *str)
{
char *ptr = strdup(str);
- if (!ptr)
- giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to duplicate string");
+ if (!ptr) giterr_set_oom();
return ptr;
}
@@ -56,7 +51,7 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
ptr = (char*)malloc(length + 1);
if (!ptr) {
- giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to duplicate string");
+ giterr_set_oom();
return NULL;
}
@@ -69,8 +64,7 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
{
void *new_ptr = realloc(ptr, size);
- if (!new_ptr)
- giterr_set(GITERR_NOMEMORY, "Out of memory. Failed to allocate %d bytes.", (int)size);
+ if (!new_ptr) giterr_set_oom();
return new_ptr;
}