#include <string.h> /* for memset() */
#include <glib/galloca.h>
#include <glib/gmessages.h>
+#include <glib/gutils.h> /* for g_snprintf(); glib-2.2.x+ it also has in <glib/gprintf.h> */
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.
*/
#define captive_strdup_alloca(string) ({ \
const gchar *_captive_strdup_alloca_string=(string); \
- gchar *_captive_strdup_alloca_r=g_alloca(strlen(_captive_strdup_alloca_string)+1); \
- strcpy(_captive_strdup_alloca_r,_captive_strdup_alloca_string); \
- (const gchar *)(_captive_strdup_alloca_string); \
+ const gchar *_captive_strdup_alloca_r=g_alloca(strlen(_captive_strdup_alloca_string)+1); \
+ strcpy((gchar *)_captive_strdup_alloca_r,_captive_strdup_alloca_string); \
+ (const gchar *)(_captive_strdup_alloca_r); \
})