https://github.com/torvalds/linux
Raw File
Tip revision: 0ce790e7d736cedc563e1fb4e998babf5a4dbc3d authored by Linus Torvalds on 29 March 2011, 19:09:47 UTC
Linux 2.6.39-rc1
Tip revision: 0ce790e
wrapper.c
/*
 * 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:
 */
static inline void release_pack_memory(size_t size __used, int flag __used)
{
}

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;
}
back to top