From ffec46fea48f1f05fbe2fb863b44fd2dd718c50f Mon Sep 17 00:00:00 2001 From: Lukas Czerner Date: Wed, 18 May 2011 14:19:52 +0200 Subject: [PATCH] e2fsprogs: Add memory allocation and zero-out helpers Add functions ext2fs_get_memzero() which will malloc() the memory using ext2fs_get_mem(), but it will zero the allocated memory afterwards with memset(). Add function ext2fs_get_arrayzero() which will use calloc() for allocating and zero-out the array. Signed-off-by: Lukas Czerner Signed-off-by: Theodore Ts'o --- lib/ext2fs/ext2fs.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index d3eb31d..888f425 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1404,13 +1404,39 @@ _INLINE_ errcode_t ext2fs_get_memalign(unsigned long size, return 0; } +_INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr) +{ + void *pp; + + pp = malloc(size); + if (!pp) + return EXT2_ET_NO_MEMORY; + memset(pp, 0, size); + memcpy(ptr, &pp, sizeof(pp)); + return 0; +} + _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr) { if (count && (-1UL)/count