2007-10-07 17:14:02 +05:30
|
|
|
/* Replacements for malloc and strdup with error checking. Too trivial
|
|
|
|
to be worth copyrighting :-). I did that because a lot of code used
|
|
|
|
malloc and strdup without checking for NULL pointer, and I like some
|
|
|
|
message better than a core dump... --marekm
|
|
|
|
|
|
|
|
Yeh, but. Remember that bailing out might leave the system in some
|
|
|
|
bizarre state. You really want to put in error checking, then add
|
|
|
|
some back-out failure recovery code. -- jfh */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "rcsid.h"
|
2007-10-07 17:15:40 +05:30
|
|
|
RCSID ("$Id: xmalloc.c,v 1.5 2004/05/06 21:31:33 kloczek Exp $")
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include "defines.h"
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
char *xmalloc (size_t size)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
ptr = malloc (size);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!ptr && size) {
|
2007-10-07 17:15:23 +05:30
|
|
|
fprintf (stderr, _("malloc(%d) failed\n"), (int) size);
|
|
|
|
exit (13);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
char *xstrdup (const char *str)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
return strcpy (xmalloc (strlen (str) + 1), str);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|