+static int
+xml_write_string(xmlTextWriter *writer, const char *name,
+ const tchar *tstr)
+{
+ if (tstr) {
+ char *utf8_str;
+ int rc = tstr_to_utf8_simple(tstr, &utf8_str);
+ if (rc)
+ return rc;
+ rc = xmlTextWriterWriteElement(writer, name, utf8_str);
+ FREE(utf8_str);
+ if (rc < 0)
+ return rc;
+ }
+ return 0;
+}
+
+static int
+xml_write_strings_from_specs(xmlTextWriter *writer,
+ const void *struct_with_strings,
+ const struct xml_string_spec specs[],
+ size_t num_specs)
+{
+ for (size_t i = 0; i < num_specs; i++) {
+ int rc = xml_write_string(writer, specs[i].name,
+ *(const tchar * const *)
+ (struct_with_strings + specs[i].offset));
+ if (rc)
+ return rc;
+ }
+ return 0;
+}
+
+static int
+dup_strings_from_specs(const void *old_struct_with_strings,
+ void *new_struct_with_strings,
+ const struct xml_string_spec specs[],
+ size_t num_specs)
+{
+ for (size_t i = 0; i < num_specs; i++) {
+ const tchar *old_str = *(const tchar * const *)
+ ((const void*)old_struct_with_strings + specs[i].offset);
+ tchar **new_str_p = (tchar **)((void*)new_struct_with_strings + specs[i].offset);
+ if (old_str) {
+ *new_str_p = TSTRDUP(old_str);
+ if (!*new_str_p)
+ return WIMLIB_ERR_NOMEM;
+ }
+ }
+ return 0;
+}