#include <unistd.h>
#include "libbb.h"
-
extern void *xmalloc(size_t size)
{
void *ptr = malloc(size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("malloc");
return ptr;
}
{
ptr = realloc(ptr, size);
if (ptr == NULL && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("realloc");
return ptr;
}
{
void *ptr = calloc(nmemb, size);
if (ptr == NULL && nmemb != 0 && size != 0)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("calloc");
return ptr;
}
-extern char * xstrdup (const char *s) {
+extern char *xstrdup(const char *s)
+{
char *t;
if (s == NULL)
return NULL;
- t = strdup (s);
+ t = strdup(s);
if (t == NULL)
- error_msg_and_die(memory_exhausted);
+ perror_msg_and_die("strdup");
return t;
}
-extern char * xstrndup (const char *s, int n) {
+extern char *xstrndup(const char *s, int n)
+{
char *t;
if (s == NULL)
error_msg_and_die("xstrndup bug");
t = xmalloc(++n);
-
- return safe_strncpy(t,s,n);
+
+ return safe_strncpy(t, s, n);
}
FILE *xfopen(const char *path, const char *mode)