lib/path: allow dir-path formatting

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2018-06-21 13:49:03 +02:00
parent 91d28f5986
commit 83bbeb77c1
2 changed files with 10 additions and 4 deletions

View File

@ -21,7 +21,7 @@ struct path_cxt {
int (*redirect_on_enoent)(struct path_cxt *, const char *, int *); int (*redirect_on_enoent)(struct path_cxt *, const char *, int *);
}; };
struct path_cxt *ul_new_path(const char *dir); struct path_cxt *ul_new_path(const char *dir, ...);
void ul_unref_path(struct path_cxt *pc); void ul_unref_path(struct path_cxt *pc);
void ul_ref_path(struct path_cxt *pc); void ul_ref_path(struct path_cxt *pc);

View File

@ -48,7 +48,7 @@ void ul_path_init_debug(void)
__UL_INIT_DEBUG_FROM_ENV(ulpath, ULPATH_DEBUG_, 0, ULPATH_DEBUG); __UL_INIT_DEBUG_FROM_ENV(ulpath, ULPATH_DEBUG_, 0, ULPATH_DEBUG);
} }
struct path_cxt *ul_new_path(const char *dir) struct path_cxt *ul_new_path(const char *dir, ...)
{ {
struct path_cxt *pc = calloc(1, sizeof(*pc)); struct path_cxt *pc = calloc(1, sizeof(*pc));
@ -61,8 +61,14 @@ struct path_cxt *ul_new_path(const char *dir)
pc->dir_fd = -1; pc->dir_fd = -1;
if (dir) { if (dir) {
pc->dir_path = strdup(dir); int rc;
if (!pc->dir_path) va_list ap;
va_start(ap, dir);
rc = vasprintf(&pc->dir_path, dir, ap);
va_end(ap);
if (rc < 0 || !pc->dir_path)
goto fail; goto fail;
} }
return pc; return pc;