提交 127cfd0d 编写于 作者: B Brad Roberts 提交者: Petr Baudis

Cleanup the x-allocation functions

xmalloc() and xrealloc() now take their sizes as size_t-type arguments.
Introduced complementary xcalloc().
Signed-off-by: NBrad Roberts <braddr@puremagic.com>
Signed-off-by: NPetr Baudis <pasky@ucw.cz>
上级 902b92e0
......@@ -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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册