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:16:07 +05:30
|
|
|
RCSID ("$Id: xmalloc.c,v 1.6 2005/03/31 05:14:50 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
|
|
|
}
|