summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
1bd5129)
Using `%zu' for the size_t value. That might be a problem on older
platforms, but we'll see. If asked for zero bytes then allocate one to
get a unique pointer.
/* Call realloc(3), exiting on NULL return. */
void *mh_xrealloc(void *, size_t);
/* Call realloc(3), exiting on NULL return. */
void *mh_xrealloc(void *, size_t);
+/* Call calloc(3), exiting on NULL return. */
void *mh_xcalloc(size_t, size_t);
void *mh_xcalloc(size_t, size_t);
char *pwd(void);
char *add(const char *, char *);
char *addlist(char *, const char *);
char *pwd(void);
char *add(const char *, char *);
char *addlist(char *, const char *);
-/*
- * Safely call calloc
- */
-void *
-mh_xcalloc(size_t nmemb, size_t size)
+/* Call calloc(3), exiting on NULL return. */
+void *mh_xcalloc(size_t nelem, size_t elsize)
- if (nmemb == 0 || size == 0)
- adios(NULL, "Tried to calloc 0 bytes");
+ if (!nelem || !elsize)
+ return mh_xmalloc(1); /* Get a unique pointer. */
- if ((memory = calloc(nmemb, size))) {
- return memory;
- } else {
- adios(NULL, "calloc failed");
- }
+ p = calloc(nelem, elsize);
+ if (!p)
+ adios(NULL, "calloc failed, size wanted: %zu * %zu", nelem, elsize);
+
+ return p;