Skip to content

Commit

Permalink
VFIL: Introduce VFIL_concat
Browse files Browse the repository at this point in the history
  • Loading branch information
walid-git committed Jan 7, 2025
1 parent 772d738 commit 574c1f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/vfil.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ void VFIL_setpath(struct vfil_path**, const char *path);
typedef int vfil_path_func_f(void *priv, const char *fn);
int VFIL_searchpath(const struct vfil_path *, vfil_path_func_f *func,
void *priv, const char *fni, char **fno);
char **VFIL_concat(const struct vfil_path *vp, const char *name);

28 changes: 28 additions & 0 deletions lib/libvarnish/vfil.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,31 @@ VFIL_searchpath(const struct vfil_path *vp, vfil_path_func_f *func, void *priv,
VSB_destroy(&vsb);
return (-1);
}

char **
VFIL_concat(const struct vfil_path *vp, const char *name)
{
struct vsb *vsb;
struct vfil_dir *vd;
char **arr;
int len = 0;

CHECK_OBJ_NOTNULL(vp, VFIL_PATH_MAGIC);
AN(name);

vsb = VSB_new_auto();
AN(vsb);
VTAILQ_FOREACH(vd, &vp->paths, list)
len++;
arr = calloc(len + 1, sizeof(char*));
len = 0;
VTAILQ_FOREACH(vd, &vp->paths, list) {
VSB_clear(vsb);
VSB_printf(vsb, "%s/%s", vd->dir, name);
AZ(VSB_finish(vsb));
arr[len++] = strdup(VSB_data(vsb));
}
arr[len] = NULL;
VSB_destroy(&vsb);
return (arr);
}

0 comments on commit 574c1f8

Please sign in to comment.