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>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
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:17:22 +05:30
|
|
|
ptr = (char *) 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
|
|
|
}
|