char *x_strndup(const char *s, size_t n);
void *x_realloc(void *ptr, size_t size);
void *x_malloc(size_t size);
+void *x_calloc(size_t nmemb, size_t size);
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
char *basename(const char *s);
char *dirname(char *s);
return ret;
}
+/* This is like calloc() but dies if the allocation fails. */
+void *
+x_calloc(size_t nmemb, size_t size)
+{
+ void *ret;
+ ret = calloc(nmemb, size);
+ if (!ret) {
+ fatal("x_calloc: Could not allocate %lu bytes", (unsigned long)size);
+ }
+ return ret;
+}
+
/*
this is like realloc() but dies if the malloc fails
*/