Code

data: Added helper functions to copy and free data.
[sysdb.git] / src / include / core / data.h
index b657486b794b16cdb9bc00560cb0b2f4ab2090dc..a5438a2c8e76d4821b29e1b6ae40aa638aea0bb8 100644 (file)
@@ -67,6 +67,30 @@ typedef struct {
        } data;
 } sdb_data_t;
 
+/*
+ * sdb_data_copy:
+ * Copy the datum stored in 'src' to the memory location pointed to by 'dst'.
+ * Any dynamic data (strings, binary data) is copied to newly allocated
+ * memory. Use, for example, sdb_data_free_datum() to free any dynamic memory
+ * stored in a datum.
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value else
+ */
+int
+sdb_data_copy(sdb_data_t *dst, const sdb_data_t *src);
+
+/*
+ * sdb_data_free_datum:
+ * Free any dynamic memory referenced by the specified datum. Does not free
+ * the memory allocated for the sdb_data_t object itself. This function must
+ * not be used if any static or stack memory is referenced from the data
+ * object.
+ */
+void
+sdb_data_free_datum(sdb_data_t *datum);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif