- * <WIM> element not the <IMAGE> element, is (for non-spit WIMs) the
- * size of the WIM file excluding the XML data and integrity table,
- * which is the current offset, since the XML data goes at the end of
- * the WIM file before the integrity table. */
- if (total_bytes == 0) {
- total_bytes = ftello(out);
- if (total_bytes == (u64)-1)
- return WIMLIB_ERR_WRITE;
+ * <WIM> element (not the <IMAGE> element), is for non-split WIMs the
+ * size of the WIM file excluding the XML data and integrity table.
+ * This should be equal to the current position in the output stream,
+ * since the XML data and integrity table are the last elements of the
+ * WIM.
+ *
+ * For split WIMs, <TOTALBYTES> takes into account the entire WIM, not
+ * just the current part. In that case, @total_bytes should be passed
+ * in to this function. */
+ if (total_bytes == 0)
+ total_bytes = start_offset;
+
+ xmlInitCharEncodingHandlers();
+
+ /* The encoding of the XML data must be UTF-16LE. */
+ encoding_handler = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF16LE);
+ if (!encoding_handler) {
+ ERROR("Failed to get XML character encoding handler for UTF-16LE");
+ ret = WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE;
+ goto out_cleanup_char_encoding_handlers;