diff options
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 16 |
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; } |