smalloc: add zeroing scalloc() variant
authorJens Axboe <axboe@fb.com>
Thu, 6 Nov 2014 22:19:31 +0000 (15:19 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 6 Nov 2014 22:19:31 +0000 (15:19 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
smalloc.c
smalloc.h

index 5fe0b6f7e57d11cdade9f103d9e8ff9dd5cbf7c1..1ba9353518813179fd3e277ae2cbeeec20a43129 100644 (file)
--- 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;
index f9a5e410fae79b570973a708c95f713912d8e40c..4b551e3e4be3fd979462371a4c866c349e2bb04e 100644 (file)
--- 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);