X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxml.c;h=2ac8cea8c71e2a50f1a78bd4534c59eb009dfbb5;hb=07319692b785446fb5aab6c455443554f9c00ec7;hp=a1e6f5960c736809230060ffc8644d50e619c3d3;hpb=034fd063f956d0806e557680a36a69a42556a776;p=wimlib diff --git a/src/xml.c b/src/xml.c index a1e6f596..2ac8cea8 100644 --- a/src/xml.c +++ b/src/xml.c @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2012 Eric Biggers + * Copyright (C) 2012, 2013 Eric Biggers * * This file is part of wimlib, a library for working with WIM files. * @@ -79,7 +79,7 @@ struct image_info { char *display_description; union { char *flags; - struct lookup_table *lookup_table; + struct wim_lookup_table *lookup_table; }; }; @@ -185,8 +185,8 @@ static u64 node_get_timestamp(const xmlNode *time_node) /* Used to sort an array of struct image_infos by their image indices. */ static int sort_by_index(const void *p1, const void *p2) { - int index_1 = ((struct image_info*)p1)->index; - int index_2 = ((struct image_info*)p1)->index; + int index_1 = ((const struct image_info*)p1)->index; + int index_2 = ((const struct image_info*)p2)->index; if (index_1 < index_2) return -1; else if (index_1 > index_2) @@ -950,14 +950,11 @@ void xml_delete_image(struct wim_info **wim_info_p, int image) wim_info = *wim_info_p; - wimlib_assert(wim_info != NULL); - wimlib_assert(image >= 1 && image <= wim_info->num_images); - destroy_image_info(&wim_info->images[image - 1]); - memcpy(&wim_info->images[image - 1], - &wim_info->images[image], - (wim_info->num_images - image) * sizeof(struct image_info)); + memmove(&wim_info->images[image - 1], + &wim_info->images[image], + (wim_info->num_images - image) * sizeof(struct image_info)); if (--wim_info->num_images == 0) { free_wim_info(wim_info); @@ -991,12 +988,12 @@ void xml_set_memory_allocator(void *(*malloc_func)(size_t), } #endif -static int calculate_dentry_statistics(struct dentry *dentry, void *arg) +static int calculate_dentry_statistics(struct wim_dentry *dentry, void *arg) { struct image_info *info = arg; - struct lookup_table *lookup_table = info->lookup_table; - const struct inode *inode = dentry->d_inode; - struct lookup_table_entry *lte; + struct wim_lookup_table *lookup_table = info->lookup_table; + const struct wim_inode *inode = dentry->d_inode; + struct wim_lookup_table_entry *lte; /* Update directory count and file count. * @@ -1048,12 +1045,12 @@ static int calculate_dentry_statistics(struct dentry *dentry, void *arg) info->hard_link_bytes += wim_resource_size(lte); } - if (inode->link_count >= 2 && dentry_is_first_in_inode(dentry)) { - for (unsigned i = 0; i < inode->num_ads; i++) { - if (inode->ads_entries[i].stream_name_len) { + if (inode->i_nlink >= 2 && dentry_is_first_in_inode(dentry)) { + for (unsigned i = 0; i < inode->i_num_ads; i++) { + if (inode->i_ads_entries[i].stream_name_len) { lte = inode_stream_lte(inode, i + 1, lookup_table); if (lte) { - info->hard_link_bytes += inode->link_count * + info->hard_link_bytes += inode->i_nlink * wim_resource_size(lte); } } @@ -1180,6 +1177,16 @@ void print_image_info(const struct wim_info *wim_info, int image) putchar('\n'); } +void libxml_global_init() +{ + xmlInitParser(); +} + +void libxml_global_cleanup() +{ + xmlCleanupParser(); +} + /* * Reads the XML data from a WIM file. */ @@ -1197,19 +1204,19 @@ int read_xml_data(FILE *fp, const struct resource_entry *res_entry, if (resource_is_compressed(res_entry)) { ERROR("XML data is supposed to be uncompressed"); ret = WIMLIB_ERR_XML; - goto out_cleanup_parser; + goto out; } if (res_entry->size < 2) { ERROR("XML data must be at least 2 bytes long"); ret = WIMLIB_ERR_XML; - goto out_cleanup_parser; + goto out; } xml_data = MALLOC(res_entry->size + 2); if (!xml_data) { ret = WIMLIB_ERR_NOMEM; - goto out_cleanup_parser; + goto out; } ret = read_uncompressed_resource(fp, res_entry->offset, @@ -1252,16 +1259,14 @@ int read_xml_data(FILE *fp, const struct resource_entry *res_entry, if (ret != 0) goto out_free_doc; - DEBUG("Freeing XML tree."); - *xml_data_ret = xml_data; xml_data = NULL; out_free_doc: + DEBUG("Freeing XML tree."); xmlFreeDoc(doc); out_free_xml_data: FREE(xml_data); -out_cleanup_parser: - xmlCleanupParser(); +out: return ret; } @@ -1325,7 +1330,7 @@ int write_xml_data(const struct wim_info *wim_info, int image, FILE *out, encoding_handler = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF16LE); if (!encoding_handler) { ERROR("Failed to get XML character encoding handler for UTF-16LE"); - ret = WIMLIB_ERR_CHAR_CONVERSION; + ret = WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE; goto out_cleanup_char_encoding_handlers; }