From 544992f770de2b98481b980e463e0492c2f2763e Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 6 Nov 2014 15:19:31 -0700 Subject: [PATCH] smalloc: add zeroing scalloc() variant Signed-off-by: Jens Axboe --- smalloc.c | 11 +++++++++++ smalloc.h | 1 + 2 files changed, 12 insertions(+) diff --git a/smalloc.c b/smalloc.c index 5fe0b6f7..1ba93535 100644 --- a/smalloc.c +++ b/smalloc.c @@ -479,6 +479,17 @@ out: return NULL; } +void *scalloc(size_t nmemb, size_t size) +{ + void *ret; + + ret = smalloc(nmemb * size); + if (ret) + memset(ret, 0, nmemb * size); + + return ret; +} + char *smalloc_strdup(const char *str) { char *ptr; diff --git a/smalloc.h b/smalloc.h index f9a5e410..4b551e3e 100644 --- a/smalloc.h +++ b/smalloc.h @@ -2,6 +2,7 @@ #define FIO_SMALLOC_H extern void *smalloc(size_t); +extern void *scalloc(size_t, size_t); extern void sfree(void *); extern char *smalloc_strdup(const char *); extern void sinit(void); -- 2.25.1