gallium/util: Add align_calloc
authorAxel Davy <axel.davy@ens.fr>
Fri, 21 Oct 2016 15:25:08 +0000 (17:25 +0200)
committerAxel Davy <axel.davy@ens.fr>
Mon, 24 Oct 2016 19:56:44 +0000 (21:56 +0200)
Add implementation for align_calloc,
which is align_malloc + memset.

v2: add if (ptr) before memset.
Fix indentation.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_memory.h

index 597df6247a68f15a9596ad1cb4d25150f7258789..66c3ba4e4106e402f6eecde6af695b4eae45c342 100644 (file)
@@ -63,6 +63,14 @@ extern "C" {
 #define align_malloc(_size, _alignment) os_malloc_aligned(_size, _alignment)
 #define align_free(_ptr) os_free_aligned(_ptr)
 
+static inline void *
+align_calloc(size_t size, unsigned long alignment)
+{
+   void *ptr = align_malloc(size, alignment);
+   if (ptr)
+      memset(ptr, 0, size);
+   return ptr;
+}
 
 /**
  * Duplicate a block of memory.