- ret = wimlib_add_image(w, dir, name, desc,
- flags_element, add_image_flags);
- if (ret != 0)
- goto done;
- ret = wimlib_overwrite(w, write_flags);
-done:
- wimlib_free(w);
+static int open_swms_from_glob(const char *swm_glob,
+ const char *first_part,
+ int open_flags,
+ WIMStruct ***additional_swms_ret,
+ unsigned *num_additional_swms_ret)
+{
+ unsigned num_additional_swms = 0;
+ WIMStruct **additional_swms = NULL;
+ glob_t globbuf;
+ int ret;
+
+ ret = glob(swm_glob, GLOB_ERR | GLOB_NOSORT, NULL, &globbuf);
+ if (ret != 0) {
+ if (ret == GLOB_NOMATCH) {
+ imagex_error("Found no files for glob \"%s\"",
+ swm_glob);
+ } else {
+ imagex_error_with_errno("Failed to process glob "
+ "\"%s\"", swm_glob);
+ }
+ ret = -1;
+ goto out;
+ }
+ num_additional_swms = globbuf.gl_pathc;
+ additional_swms = calloc(num_additional_swms, sizeof(additional_swms[0]));
+ if (!additional_swms) {
+ imagex_error("Out of memory");
+ ret = -1;
+ goto out_globfree;
+ }
+ size_t offset = 0;
+ for (size_t i = 0; i < num_additional_swms; i++) {
+ if (strcmp(globbuf.gl_pathv[i], first_part) == 0) {
+ offset++;
+ continue;
+ }
+ ret = wimlib_open_wim(globbuf.gl_pathv[i],
+ open_flags | WIMLIB_OPEN_FLAG_SPLIT_OK,
+ &additional_swms[i - offset]);
+ if (ret != 0)
+ goto out_close_swms;
+ }
+ *additional_swms_ret = additional_swms;
+ *num_additional_swms_ret = num_additional_swms - offset;
+ ret = 0;
+ goto out_globfree;
+out_close_swms:
+ for (unsigned i = 0; i < num_additional_swms; i++)
+ wimlib_free(additional_swms[i]);
+ free(additional_swms);
+out_globfree:
+ globfree(&globbuf);
+out: