1999-09-23 00:34:08 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
2000-04-13 18:41:31 +08:00
|
|
|
#if !defined(EXIT_FAILURE)
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
#endif
|
|
|
|
|
1999-09-23 00:34:08 +08:00
|
|
|
void *vmefail(void)
|
|
|
|
{
|
2000-03-01 07:22:44 +08:00
|
|
|
fprintf(stderr, _("memory alloc returned NULL.\n"));
|
1999-09-29 23:59:55 +08:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
/*@notreached@*/
|
1999-09-23 00:34:08 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !(HAVE_MCHECK_H && defined(__GNUC__))
|
|
|
|
|
|
|
|
void * xmalloc (size_t size)
|
|
|
|
{
|
2000-03-01 07:22:44 +08:00
|
|
|
register void *value;
|
|
|
|
if (size == 0) size++;
|
|
|
|
value = malloc (size);
|
1999-09-23 00:34:08 +08:00
|
|
|
if (value == 0)
|
|
|
|
value = vmefail();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * xcalloc (size_t nmemb, size_t size)
|
|
|
|
{
|
2000-03-01 07:22:44 +08:00
|
|
|
register void *value;
|
|
|
|
if (size == 0) size++;
|
|
|
|
if (nmemb == 0) nmemb++;
|
|
|
|
value = calloc (nmemb, size);
|
1999-09-23 00:34:08 +08:00
|
|
|
if (value == 0)
|
|
|
|
value = vmefail();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * xrealloc (void *ptr, size_t size)
|
|
|
|
{
|
2000-03-01 07:22:44 +08:00
|
|
|
register void *value;
|
|
|
|
if (size == 0) size++;
|
|
|
|
value = realloc (ptr, size);
|
1999-09-23 00:34:08 +08:00
|
|
|
if (value == 0)
|
|
|
|
value = vmefail();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * xstrdup (const char *str)
|
|
|
|
{
|
|
|
|
char *newstr = (char *) malloc (strlen(str) + 1);
|
|
|
|
if (newstr == 0)
|
|
|
|
newstr = (char *) vmefail();
|
|
|
|
strcpy (newstr, str);
|
|
|
|
return newstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !(HAVE_MCHECK_H && defined(__GNUC__)) */
|