From a6935806d2330ad86915a76f6807328d445d63f3 Mon Sep 17 00:00:00 2001 From: Martin Nagy Date: Tue, 10 Feb 2009 18:55:12 +0100 Subject: Add memory allocation convenience helpers. --- util.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'util.h') diff --git a/util.h b/util.h index 4eb834b..18b37d7 100644 --- a/util.h +++ b/util.h @@ -25,6 +25,27 @@ if (result != ISC_R_SUCCESS) goto cleanup; \ } while (0) +#define CHECKED_MEM_GET(m, target_ptr, s) \ + do { \ + (target_ptr) = isc_mem_get((m), (s)); \ + if ((target_ptr) == NULL) { \ + result = ISC_R_NOMEMORY; \ + goto cleanup; \ + } \ + } while (0) + +#define CHECKED_MEM_GET_PTR(m, target_ptr) \ + CHECKED_MEM_GET(m, target_ptr, sizeof(*(target_ptr))) + +#define CHECKED_MEM_STRDUP(m, source, target) \ + do { \ + (target) = isc_mem_strdup((m), (source)); \ + if ((target) == NULL) { \ + result = ISC_R_NOMEMORY; \ + goto cleanup; \ + } \ + } while (0) + #define ZERO_PTR(ptr) memset((ptr), 0, sizeof(*(ptr))) #endif /* !_LD_UTIL_H_ */ -- cgit