From: Peter Verthez Date: Sun, 5 Jan 2003 17:46:44 +0000 (+0000) Subject: New function gom_set_xref_value. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=295e0273f2ff3bb95f7afb1ac639ab7203672c9c;p=gedcom-parse.git New function gom_set_xref_value. --- diff --git a/gom/gom_modify.c b/gom/gom_modify.c index 3da2fa8..82205ff 100644 --- a/gom/gom_modify.c +++ b/gom/gom_modify.c @@ -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; +}