X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Fgom_modify.c;h=82205ffb4ca03cc02548ac0ed131aa9a748313b9;hb=d2d823fd4fe80162765029e5bc29f9b4f6f968f5;hp=3da2fa88e01c54f53dc820a5b269e97fb775e771;hpb=ffaf74cec71efb6bf1d3c7058105ffa0863836d4;p=gedcom-parse.git 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; +}