From 574c1f8c2a96719d0696036318fd1ef323896a65 Mon Sep 17 00:00:00 2001 From: Walid Boudebouda Date: Tue, 7 Jan 2025 14:40:40 +0100 Subject: [PATCH] VFIL: Introduce VFIL_concat --- include/vfil.h | 1 + lib/libvarnish/vfil.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/vfil.h b/include/vfil.h index 1f72c230589..4f74d7bda07 100644 --- a/include/vfil.h +++ b/include/vfil.h @@ -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); diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c index 71debaeee5d..669c3629b84 100644 --- a/lib/libvarnish/vfil.c +++ b/lib/libvarnish/vfil.c @@ -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); +}