X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxml.c;h=cd335e07d65fa4a72a09223699484b382c7aa8ce;hb=67b6e421c8018a894f38eee258dbc03510137254;hp=b22bc0945f4e9466ee4dac2f41a49ce9a2bf0a59;hpb=2254a0fc3f1d7af1151ee83f3458f44339b5028b;p=wimlib diff --git a/src/xml.c b/src/xml.c index b22bc094..cd335e07 100644 --- a/src/xml.c +++ b/src/xml.c @@ -752,7 +752,11 @@ xml_write_windows_version(xmlTextWriter *writer, if (rc < 0) return rc; - return xmlTextWriterEndElement(writer); /* */ + rc = xmlTextWriterEndElement(writer); /* */ + if (rc < 0) + return rc; + + return 0; } /* Writes the information contained in a `struct windows_info' to the XML @@ -802,16 +806,19 @@ xml_write_windows_info(xmlTextWriter *writer, if (windows_info->windows_version_exists) { rc = xml_write_windows_version(writer, &windows_info->windows_version); - if (rc < 0) + if (rc) return rc; } - rc = xml_write_string(writer, "SYSTEMROOT", - windows_info->system_root); + rc = xml_write_string(writer, "SYSTEMROOT", windows_info->system_root); if (rc) return rc; - return xmlTextWriterEndElement(writer); /* */ + rc = xmlTextWriterEndElement(writer); /* */ + if (rc < 0) + return rc; + + return 0; } /* Writes a time element to the XML document being constructed in memory. */ @@ -897,6 +904,7 @@ xml_write_image_info(xmlTextWriter *writer, const struct image_info *image_info) rc = xmlTextWriterEndElement(writer); /* */ if (rc < 0) return rc; + return 0; } @@ -1480,6 +1488,7 @@ out_output_buffer_close: out_buffer_free: xmlBufferFree(buf); out: + DEBUG("ret=%d", ret); return ret; out_write_error: @@ -1513,11 +1522,13 @@ write_wim_xml_data(WIMStruct *wim, int image, u64 total_bytes, WIM_RESHDR_FLAG_METADATA, &wim->out_fd, WIMLIB_COMPRESSION_TYPE_NONE, + 0, out_res_entry, NULL, write_resource_flags, &wim->lzx_context); FREE(xml_data); + DEBUG("ret=%d"); return ret; } @@ -1554,30 +1565,34 @@ wimlib_image_name_in_use(const WIMStruct *wim, const tchar *name) /* API function documented in wimlib.h */ WIMLIBAPI int -wimlib_extract_xml_data(WIMStruct *wim, FILE *fp) +wimlib_get_xml_data(WIMStruct *wim, void **buf_ret, size_t *bufsize_ret) { - size_t size; - void *buf; - int ret; + if (wim->filename == NULL) + return WIMLIB_ERR_INVALID_PARAM; - if (!wim->filename) + if (buf_ret == NULL || bufsize_ret == NULL) return WIMLIB_ERR_INVALID_PARAM; - ret = res_entry_to_data(&wim->hdr.xml_res_entry, wim, &buf); + *bufsize_ret = wim->hdr.xml_res_entry.original_size; + return res_entry_to_data(&wim->hdr.xml_res_entry, wim, buf_ret); +} + +WIMLIBAPI int +wimlib_extract_xml_data(WIMStruct *wim, FILE *fp) +{ + int ret; + void *buf; + size_t bufsize; + + ret = wimlib_get_xml_data(wim, &buf, &bufsize); if (ret) - goto out; + return ret; - size = wim->hdr.xml_res_entry.original_size; - if (fwrite(buf, 1, size, fp) != size) { + if (fwrite(buf, 1, bufsize, fp) != bufsize) { ERROR_WITH_ERRNO("Failed to extract XML data"); ret = WIMLIB_ERR_WRITE; - goto out_free_buf; } - - ret = 0; -out_free_buf: FREE(buf); -out: return ret; }