* Extracts the XML data of a WIM file to a file stream. Every WIM file
* includes a string of XML that describes the images contained in the WIM.
*
+ * See wimlib_get_xml_data() to read the XML data into memory instead.
+ *
* @param wim
* Pointer to the ::WIMStruct for a WIM file, which does not necessarily
* have to be standalone (e.g. it could be part of a split WIM).
extern int
wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info);
+/**
+ * @ingroup G_wim_information
+ *
+ * Read the XML data of a WIM file into an in-memory buffer. Every WIM file
+ * includes a string of XML that describes the images contained in the WIM.
+ *
+ * See wimlib_extract_xml_data() to extract the XML data to a file stream
+ * instead.
+ *
+ * @param wim
+ * Pointer to the ::WIMStruct for a WIM file, which does not necessarily
+ * have to be standalone (e.g. it could be part of a split WIM).
+ * @param buf_ret
+ * On success, a pointer to an allocated buffer containing the raw UTF16-LE
+ * XML data is written to this location.
+ * @param bufsize_ret
+ * The size of the XML data in bytes is written to this location.
+ *
+ * @return 0 on success; nonzero on error.
+ * @retval ::WIMLIB_ERR_INVALID_PARAM
+ * @p wim is not a ::WIMStruct that was created by wimlib_open_wim(), or
+ * @p buf_ret or @p bufsize_ret was @c NULL.
+ * @retval ::WIMLIB_ERR_NOMEM
+ * @retval ::WIMLIB_ERR_READ
+ * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
+ * Failed to read the XML data from the WIM.
+ */
+extern int
+wimlib_get_xml_data(WIMStruct *wim, void **buf_ret, size_t *bufsize_ret);
+
/**
* @ingroup G_general
*
/* 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;
}