示例#1
0
文件: xmalloc.c 项目: 0day-ci/gcc
PTR
xmalloc (size_t size)
{
  PTR newmem;

  if (size == 0)
    size = 1;
  newmem = malloc (size);
  if (!newmem)
    xmalloc_failed (size);

  return (newmem);
}
示例#2
0
文件: xmalloc.c 项目: 0day-ci/gcc
PTR
xcalloc (size_t nelem, size_t elsize)
{
  PTR newmem;

  if (nelem == 0 || elsize == 0)
    nelem = elsize = 1;

  newmem = calloc (nelem, elsize);
  if (!newmem)
    xmalloc_failed (nelem * elsize);

  return (newmem);
}
示例#3
0
文件: xmalloc.c 项目: 0day-ci/gcc
PTR
xrealloc (PTR oldmem, size_t size)
{
  PTR newmem;

  if (size == 0)
    size = 1;
  if (!oldmem)
    newmem = malloc (size);
  else
    newmem = realloc (oldmem, size);
  if (!newmem)
    xmalloc_failed (size);

  return (newmem);
}
示例#4
0
/*
 * Change the size of an allocated block of memory P to N bytes,
 * with error checking.
 * If P is NULL, run xmalloc.
 * If N is 0, run free and return NULL.
 */
void *
xrealloc(void *p, size_t n)
{
	if (p == 0) {
		return xmalloc(n);
	}
	if (n == 0) {
		free(p);
		return 0;
	}
	p = realloc(p, n);
	if (p == 0) {
		xmalloc_failed();
	}
	return p;
}