Definition of MAKELINKFUNC.
[gedcom-parse.git] / gom / gom_modify.c
index bff22cd6de22d8fe1803ae36dbff588e8328a9bd..82205ffb4ca03cc02548ac0ed131aa9a748313b9 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "utf8.h"
+#include "utf8tools.h"
 #include "gom.h"
 #include "gom_internal.h"
 
@@ -77,3 +77,30 @@ char* gom_set_string_for_locale(char** data, const char* locale_str)
 
   return result;
 }
+
+struct xref_value* gom_set_xref_value(struct xref_value** data,
+                                     struct xref_value* newval)
+{
+  struct xref_value* result = NULL;
+  if (data) {
+    /* Unreference the old value if not NULL */
+    if (*data)
+      result = gedcom_unlink_xref((*data)->type, (*data)->string);
+    else
+      result = newval;
+
+    /* Reference the new value if not NULL */
+    if (result != NULL && newval) {
+      result = gedcom_link_xref(newval->type, newval->string);
+      /* On error, perform rollback to old value (guaranteed to work) */
+      if (result == NULL)
+       gedcom_link_xref((*data)->type, (*data)->string);
+    }
+    
+    if (result != NULL) {
+      *data = newval;
+      result = newval;
+    }
+  }
+  return result;
+}