Add wimlib_get_xml_data() API
[wimlib] / src / xml.c
index 5258aaf..deeedb5 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -1564,30 +1564,34 @@ wimlib_image_name_in_use(const WIMStruct *wim, const tchar *name)
 
 /* API function documented in wimlib.h  */
 WIMLIBAPI int
 
 /* 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;
 
                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)
        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;
                ERROR_WITH_ERRNO("Failed to extract XML data");
                ret = WIMLIB_ERR_WRITE;
-               goto out_free_buf;
        }
        }
-
-       ret = 0;
-out_free_buf:
        FREE(buf);
        FREE(buf);
-out:
        return ret;
 }
 
        return ret;
 }