#include <stdio.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#else
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#endif
#if ENABLE_NLS
#include <libintl.h>
#define _(String) gettext (String)
#else
#define _(String) String
#endif
void *
xmalloc (size)
size_t size;
{
void *ptr;
ptr = malloc (size);
if (ptr == NULL)
{
fprintf (stderr, _("xmalloc(): couldn't allocate %d bytes\n"), size);
exit (1);
}
return ptr;
}
void *
xcalloc (num, size)
size_t num;
size_t size;
{
void *ptr;
ptr = calloc (num, size);
if (ptr == NULL)
{
fprintf (stderr, _("xcalloc(): couldn't allocate %d bytes\n"), size);
exit (1);
}
return ptr;
}
void *
xrealloc (ptr, size)
void *ptr;
size_t size;
{
void *nptr;
if (ptr == NULL)
return xmalloc (size);
nptr = realloc (ptr, size);
if (nptr == NULL)
{
fprintf (stderr, _("xrealloc(): couldn't reallocate %d bytes\n"), size);
exit (1);
}
return nptr;
}
void
xfree (ptr)
void *ptr;
{
if (ptr == NULL)
return;
free (ptr);
}
char *
xstrdup (str)
char *str;
{
char *tmp;
tmp = xmalloc (strlen (str) + 1);
strcpy (tmp, str);
return tmp;
}