From f08ae22dbedf5cadfb5183921bec40eb21edeaed Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 9 Jun 2011 14:23:21 +0200 Subject: [PATCH] Macros LIBISO_ALLOC_MEM, LIBISO_FREE_MEM for replaceing local variables --- libisofs/util.c | 10 ++++++++++ libisofs/util.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libisofs/util.c b/libisofs/util.c index 08ec9f1..598e9c1 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -1886,4 +1886,14 @@ ex:; return ret; } + +void *iso_alloc_mem(size_t size, size_t count, int flag) +{ + void *pt; + + pt = calloc(size, count); + if(pt == NULL) + iso_msg_submit(-1, ISO_OUT_OF_MEM, 0, "Out of virtual memory"); + return pt; +} diff --git a/libisofs/util.h b/libisofs/util.h index c0a1aa1..d3062fe 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -539,4 +539,18 @@ int checksum_md5_xinfo_cloner(void *old_data, void **new_data, int flag); /* ------------------------------------------------------------------------- */ +void *iso_alloc_mem(size_t size, size_t count, int flag); + +#define LIBISO_ALLOC_MEM(pt, typ, count) { \ + pt= (typ *) iso_alloc_mem(sizeof(typ), (size_t) (count), 0); \ + if(pt == NULL) { \ + ret= -1; goto ex; \ + } } + +#define LIBISO_FREE_MEM(pt) { \ + if(pt != NULL) \ + free((char *) pt); \ + } + + #endif /*LIBISO_UTIL_H_*/