#include "xalloc.h"

#include <stdio.h>

static void __attribute__ ((noreturn))
memory_exhausted (void)
{
  fprintf (stderr, "Memory exhausted.\n");
  abort ();
}

void *
_sigsum_xalloc (size_t size)
{
  void *p = malloc (size);
  if (!p)
    memory_exhausted ();

  return p;
}

void *
_sigsum_xrealloc (void *p, size_t size)
{
  p = realloc (p, size);
  /* If size == 0, returning NULL is not an error. */
  if (size > 0 && !p)
    memory_exhausted ();

  return p;
}
