]> wimlib.net Git - wimlib/commitdiff
Add wimlib_get_xml_data() API
authorEric Biggers <ebiggers3@gmail.com>
Sat, 7 Dec 2013 01:04:19 +0000 (19:04 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 7 Dec 2013 19:40:45 +0000 (13:40 -0600)
include/wimlib.h
src/xml.c

index ca16d9404a60a5b23268612f435643fa0adb9437..7bab4a34170e1a36ce2505cb29e82dabadc78147 100644 (file)
@@ -2374,6 +2374,8 @@ wimlib_extract_image_from_pipe(int pipe_fd,
  * 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.
  *
  * 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).
  * @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).
@@ -2498,6 +2500,36 @@ wimlib_get_image_name(const WIMStruct *wim, int image);
 extern int
 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info);
 
 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
  *
 /**
  * @ingroup G_general
  *
index 5258aaf4cfacb7275e1d8203195668b09680c20d..deeedb50efba04f5088e52615f66380124846c8f 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;
 }