From: Lukas Czerner Date: Wed, 18 May 2011 12:19:52 +0000 (+0200) Subject: e2fsprogs: Add memory allocation and zero-out helpers X-Git-Tag: v1.42-WIP-0702~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffec46fea48f1f05fbe2fb863b44fd2dd718c50f;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index d3eb31df3..888f4251e 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