/*
* Utility routines.
*
- * Copyright (C) tons of folks. Tracking down who wrote what
- * isn't something I'm going to worry about... If you wrote something
- * here, please feel free to acknowledge your work.
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
- * Permission has been granted to redistribute this code under the GPL.
- *
*/
#include <stdio.h>
extern void *xmalloc(size_t size)
{
void *ptr = malloc(size);
-
- if (!ptr)
+ if (ptr == NULL && size != 0)
error_msg_and_die(memory_exhausted);
return ptr;
}
-extern void *xrealloc(void *old, size_t size)
+extern void *xrealloc(void *ptr, size_t size)
{
- void *ptr = realloc(old, size);
- if (!ptr)
+ ptr = realloc(ptr, size);
+ if (ptr == NULL && size != 0)
error_msg_and_die(memory_exhausted);
return ptr;
}
extern void *xcalloc(size_t nmemb, size_t size)
{
void *ptr = calloc(nmemb, size);
- if (!ptr)
+ if (ptr == NULL && nmemb != 0 && size != 0)
error_msg_and_die(memory_exhausted);
return ptr;
}
return fp;
}
+/* Stupid gcc always includes its own builtin strlen()... */
+#undef strlen
+size_t xstrlen(const char *string)
+{
+ return(strlen(string));
+}
+
/* END CODE */
/*
Local Variables: