summaryrefslogtreecommitdiffstats
path: root/util.h
diff options
context:
space:
mode:
authorMartin Nagy <mnagy@redhat.com>2009-02-10 18:55:12 +0100
committerMartin Nagy <mnagy@redhat.com>2009-02-12 15:39:48 +0100
commita6935806d2330ad86915a76f6807328d445d63f3 (patch)
treec53818e7bc7ef4508aea4a7be36d3ea13c71bae3 /util.h
parentb2535930e5fb49bf2ad66f850c74cfeaba94cff5 (diff)
downloadldap_driver_testing-a6935806d2330ad86915a76f6807328d445d63f3.tar.gz
ldap_driver_testing-a6935806d2330ad86915a76f6807328d445d63f3.tar.xz
ldap_driver_testing-a6935806d2330ad86915a76f6807328d445d63f3.zip
Add memory allocation convenience helpers.
Diffstat (limited to 'util.h')
-rw-r--r--util.h21
1 files changed, 21 insertions, 0 deletions
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_ */