-
-struct expanded_paths_ctx {
- tchar **expanded_paths;
- size_t num_expanded_paths;
- size_t alloc_length;
-};
-
-static int
-append_path_cb(const tchar *path, void *_ctx, bool may_need_trans)
-{
- struct expanded_paths_ctx *ctx = _ctx;
- tchar *path_dup;
-
- if (ctx->num_expanded_paths == ctx->alloc_length) {
- tchar **new_paths;
- size_t new_alloc_length = max(ctx->alloc_length + 8,
- ctx->alloc_length * 3 / 2);
-
- new_paths = REALLOC(ctx->expanded_paths,
- new_alloc_length * sizeof(new_paths[0]));
- if (new_paths == NULL)
- return WIMLIB_ERR_NOMEM;
- ctx->expanded_paths = new_paths;
- ctx->alloc_length = new_alloc_length;
- }
- path_dup = TSTRDUP(path);
- if (path_dup == NULL)
- return WIMLIB_ERR_NOMEM;
- if (may_need_trans) {
- for (tchar *p = path_dup; *p; p++)
- if (is_any_path_separator(*p))
- *p = WIM_PATH_SEPARATOR;
- }
- ctx->expanded_paths[ctx->num_expanded_paths++] = path_dup;
- return 0;
-}
-
-int
-expand_wildcard_wim_paths(WIMStruct *wim,
- const tchar * const *wildcards,
- size_t num_wildcards,
- tchar ***expanded_paths_ret,
- size_t *num_expanded_paths_ret,
- u32 flags)
-{
- int ret;
- struct expanded_paths_ctx ctx = {
- .expanded_paths = NULL,
- .num_expanded_paths = 0,
- .alloc_length = 0,
- };
- for (size_t i = 0; i < num_wildcards; i++) {
- ret = expand_wildcard(wim, wildcards[i], append_path_cb, &ctx,
- flags);
- if (ret)
- goto out_free;
- }
- *expanded_paths_ret = ctx.expanded_paths;
- *num_expanded_paths_ret = ctx.num_expanded_paths;
- return 0;
-
-out_free:
- for (size_t i = 0; i < ctx.num_expanded_paths; i++)
- FREE(ctx.expanded_paths[i]);
- FREE(ctx.expanded_paths);
- return ret;
-}