aboutsummaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorBrad Roberts <braddr@puremagic.com>2005-05-14 19:04:25 -0700
committerPetr Baudis <xpasky@machine.sinus.cz>2005-05-15 11:58:12 +0200
commit127cfd0d2f1db6ef690e01aafd1c660ea1c82499 (patch)
tree69a33292d2e84b3830583592ff19e94cb6a4ecb6 /cache.h
parent902b92e00e491a60d55c4b2bce122903b8347f34 (diff)
downloadgit-127cfd0d2f1db6ef690e01aafd1c660ea1c82499.tar.gz
git-127cfd0d2f1db6ef690e01aafd1c660ea1c82499.tar.xz
Cleanup the x-allocation functions
xmalloc() and xrealloc() now take their sizes as size_t-type arguments. Introduced complementary xcalloc(). Signed-off-by: Brad Roberts <braddr@puremagic.com> Signed-off-by: Petr Baudis <pasky@ucw.cz>
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/cache.h b/cache.h
index c06b94107..7696766dd 100644
--- a/cache.h
+++ b/cache.h
@@ -179,7 +179,7 @@ const char *show_date(unsigned long time, int timezone);
void parse_date(char *date, char *buf, int bufsize);
void datestamp(char *buf, int bufsize);
-static inline void *xmalloc(int size)
+static inline void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret)
@@ -187,7 +187,7 @@ static inline void *xmalloc(int size)
return ret;
}
-static inline void *xrealloc(void *ptr, int size)
+static inline void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
if (!ret)
@@ -195,4 +195,12 @@ static inline void *xrealloc(void *ptr, int size)
return ret;
}
+static inline void *xcalloc(size_t nmemb, size_t size)
+{
+ void *ret = calloc(nmemb, size);
+ if (!ret)
+ die("Out of memory, calloc failed");
+ return ret;
+}
+
#endif /* CACHE_H */