1999-09-23 00:34:08 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
void *vmefail(void)
|
|
|
|
{
|
1999-09-29 23:59:55 +08:00
|
|
|
fprintf(stderr, _("virtual memory exhausted.\n"));
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
register void *value = malloc (size);
|
|
|
|
if (value == 0)
|
|
|
|
value = vmefail();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * xcalloc (size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
register void *value = calloc (nmemb, size);
|
|
|
|
if (value == 0)
|
|
|
|
value = vmefail();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * xrealloc (void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
register void *value = realloc (ptr, size);
|
|
|
|
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__)) */
|