aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eprintf.c12
-rw-r--r--eprintf.h9
2 files changed, 17 insertions, 4 deletions
diff --git a/eprintf.c b/eprintf.c
index 7a885b3..41c043f 100644
--- a/eprintf.c
+++ b/eprintf.c
@@ -76,6 +76,18 @@ void *emalloc(size_t n)
return p;
}
+/* ecalloc: attempt to allocate memory or exit on error */
+void *ecalloc(size_t nmemb, size_t size)
+{
+ void *p;
+
+ p = calloc(nmemb, size);
+ if (p == NULL)
+ eprintf("ecalloc(%zu, %zu) failed:", nmemb, size);
+
+ return p;
+}
+
/* erealloc: attempt to reallocate memory or exit on error */
void *erealloc(void *p, size_t n)
{
diff --git a/eprintf.h b/eprintf.h
index aecc3a6..bfe4ca8 100644
--- a/eprintf.h
+++ b/eprintf.h
@@ -6,10 +6,11 @@ noreturn void eprintf(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
void weprintf(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
-char *estrdup(const char *);
-void *emalloc(size_t);
-void *erealloc(void *, size_t);
+char *estrdup(const char *str);
+void *emalloc(size_t size);
+void *ecalloc(size_t nmemb, size_t size);
+void *erealloc(void *p, size_t size);
char *progname(void);
-void setprogname(const char *);
+void setprogname(const char *name);
#endif /* !EPRINTF_H */