+/*
+ * Verify that a list of WIM files sorted by part number is a spanned set.
+ *
+ * Return: 0 on success; WIMLIB_ERR_SPLIT_INVALID if the set is not valid.
+ */
+static int
+verify_swm_set(WIMStruct * const *swms, unsigned num_swms)
+{
+ for (unsigned i = 0; i < num_swms; i++) {
+ if (!guids_equal(swms[i]->hdr.guid, swms[0]->hdr.guid)) {
+ ERROR("The split WIM parts specified belong to "
+ "different split WIMs!");
+ return WIMLIB_ERR_SPLIT_INVALID;
+ }
+ if (swms[i]->hdr.total_parts != num_swms) {
+ ERROR("\"%"TS"\" says there are %u parts in the split "
+ "WIM, but %s%u part%s provided",
+ swms[i]->filename, swms[i]->hdr.total_parts,
+ num_swms < swms[i]->hdr.total_parts ? "only ":"",
+ num_swms, num_swms > 1 ? "s were" : " was");
+ return WIMLIB_ERR_SPLIT_INVALID;
+ }
+ if (swms[i]->hdr.part_number != i + 1) {
+ ERROR("The parts of the split WIM are not numbered "
+ "1..%u as expected. Did you specify duplicate "
+ "parts?", num_swms);
+ return WIMLIB_ERR_SPLIT_INVALID;
+ }
+ }
+ return 0;
+}
+
+static int
+cmp_swms_by_part_number(const void *p1, const void *p2)
+{
+ WIMStruct *swm1 = *(WIMStruct **)p1;
+ WIMStruct *swm2 = *(WIMStruct **)p2;
+
+ return (int)swm1->hdr.part_number - (int)swm2->hdr.part_number;
+}
+