X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fsplit.c;h=b8cb67896e57743eec0e768455260f9c76dbfcdd;hb=e0beab67ce67493da928a9fe5957c1f258073b9a;hp=f22780bbae654b73eb7d6a3c6c5299c3c183eb14;hpb=4f9947253f6a08f4a922d3efe0880e3039b3eb5e;p=wimlib diff --git a/src/split.c b/src/split.c index f22780bb..b8cb6789 100644 --- a/src/split.c +++ b/src/split.c @@ -2,23 +2,25 @@ * split.c * * Split a WIM file into parts. - * + */ + +/* * Copyright (C) 2012 Eric Biggers * - * wimlib - Library for working with WIM files + * This file is part of wimlib, a library for working with WIM files. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) any - * later version. + * wimlib is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) + * any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * You should have received a copy of the GNU Lesser General Public License along - * with this library; if not, write to the Free Software Foundation, Inc., 59 - * Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License + * along with wimlib; if not, see http://www.gnu.org/licenses/. */ #include "wimlib_internal.h" @@ -47,7 +49,7 @@ static int finish_swm(WIMStruct *w, struct lookup_table_entry *lte_chain_head, off_t lookup_table_offset = ftello(w->out_fp); int ret; - DEBUG("Writing lookup table for SWM (offset %"PRIu64")\n", + DEBUG("Writing lookup table for SWM (offset %"PRIu64")", lookup_table_offset); while (lte_chain_head != NULL) { @@ -55,7 +57,7 @@ static int finish_swm(WIMStruct *w, struct lookup_table_entry *lte_chain_head, if (ret != 0) return ret; struct lookup_table_entry *prev = lte_chain_head; - lte_chain_head = prev->next_lte_in_swm; + lte_chain_head = lte_chain_head->next_lte_in_swm; prev->next_lte_in_swm = NULL; } off_t xml_data_offset = ftello(w->out_fp); @@ -80,7 +82,6 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) { struct args *args = (struct args*)__args; WIMStruct *w = args->w; - FILE *out_fp = w->out_fp; int ret; /* metadata resources were already written. */ @@ -106,12 +107,12 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) if (args->write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS) printf("Writing `%s' (%"PRIu64" of %"PRIu64" bytes, " - "%.0f%% done)\n", - args->swm_base_name, - args->total_bytes_written, - args->total_bytes, - (double)args->total_bytes_written / - (double)args->total_bytes * 100.0); + "%.0f%% done)\n", + args->swm_base_name, + args->total_bytes_written, + args->total_bytes, + (double)args->total_bytes_written / + (double)args->total_bytes * 100.0); ret = begin_write(w, args->swm_base_name, args->write_flags); if (ret != 0) @@ -183,10 +184,11 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, w->write_metadata = true; for (int i = 0; i < w->hdr.image_count; i++) { - struct lookup_table_entry *metadata_lte; - metadata_lte = w->image_metadata[i].lookup_table_entry; + DEBUG("Writing metadata resource %d", i); + + metadata_lte = w->image_metadata[i].metadata_lte; ret = copy_resource(metadata_lte, w); if (ret != 0) return ret; @@ -239,22 +241,23 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, FILE *fp = fopen(p, "r+b"); if (!fp) { - ERROR("Failed to open `%s': %m\n", p); + ERROR_WITH_ERRNO("Failed to open `%s'", p); return WIMLIB_ERR_OPEN; } - char buf[4]; - put_u16(buf, i); - put_u16(buf + 2, total_parts); + u8 buf[4]; + put_u16(&buf[0], i); + put_u16(&buf[2], total_parts); if (fseek(fp, 40, SEEK_SET) != 0 || fwrite(buf, 1, sizeof(buf), fp) != sizeof(buf) || fclose(fp) != 0) { - ERROR("Error overwriting header of `%s': %m\n", name); + ERROR_WITH_ERRNO("Error overwriting header of `%s'", + name); return WIMLIB_ERR_WRITE; } } if (write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS) - printf("Done!\n"); + puts("Done!"); wimlib_free(w); return 0; }