+captive_memdup()
authorshort <>
Fri, 28 Mar 2003 09:51:45 +0000 (09:51 +0000)
committershort <>
Fri, 28 Mar 2003 09:51:45 +0000 (09:51 +0000)
src/libcaptive/include/captive/macros.h

index 0259c49..f30843e 100644 (file)
@@ -206,6 +206,28 @@ G_BEGIN_DECLS
 
 
 /**
+ * captive_memdup:
+ * @destp: Variable with the pointer to the target object wished to be allocated.
+ * Original value is discarded.
+ * @srcp: Pointer to the source object to be copied to @destp.
+ *
+ * Macro to similiar to g_memdup() but the object size is detected automatically.
+ * Size of @destp object and @srcp object must be the same.
+ * 
+ * You must free the allocated memory of @destp by g_free().
+ * 
+ * @Returns: Initialized @destp value as the copied memory of size #sizeof(typeof(*srcp)).
+ */
+#define captive_memdup(destp,srcp) ({ \
+               typeof(&(destp)) _captive_captive_memdup_destpp=&(destp); \
+               g_assert(sizeof(*(destp))==sizeof(*(srcp))); \
+               captive_new(*_captive_captive_memdup_destpp); \
+               memcpy(*_captive_captive_memdup_destpp,(srcp),sizeof(*(srcp))); \
+               (*_captive_captive_memdup_destpp); \
+               })
+
+
+/**
  * captive_va_arg:
  * @objp: Variable to be filled from the next argument of @ap.
  * @ap: Initialized #va_list type.