2009-04-20 15:00:56 +02:00
|
|
|
/*
|
|
|
|
* Various trivial helper wrappers around standard functions
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's no pack memory to release - but stay close to the Git
|
|
|
|
* version so wrap this away:
|
|
|
|
*/
|
2012-09-11 00:15:03 +02:00
|
|
|
static inline void release_pack_memory(size_t size __maybe_unused,
|
|
|
|
int flag __maybe_unused)
|
2009-04-20 15:00:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
char *xstrdup(const char *str)
|
|
|
|
{
|
|
|
|
char *ret = strdup(str);
|
|
|
|
if (!ret) {
|
|
|
|
release_pack_memory(strlen(str) + 1, -1);
|
|
|
|
ret = strdup(str);
|
|
|
|
if (!ret)
|
|
|
|
die("Out of memory, strdup failed");
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *xrealloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *ret = realloc(ptr, size);
|
|
|
|
if (!ret && !size)
|
|
|
|
ret = realloc(ptr, 1);
|
|
|
|
if (!ret) {
|
|
|
|
release_pack_memory(size, -1);
|
|
|
|
ret = realloc(ptr, size);
|
|
|
|
if (!ret && !size)
|
|
|
|
ret = realloc(ptr, 1);
|
|
|
|
if (!ret)
|
|
|
|
die("Out of memory, realloc failed");
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|