]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: allow dir-path formatting
authorKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2018 11:49:03 +0000 (13:49 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2018 11:49:03 +0000 (13:49 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/path.h
lib/path.c

index f372c75027f7ce3356a0863875c0784154e50125..b36a735f31cc9d1ee1446e486788c27bdf1709bb 100644 (file)
@@ -21,7 +21,7 @@ struct path_cxt {
        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_ref_path(struct path_cxt *pc);
 
index 602674956a400fe235ea14cc59aac8cfdae13fde..34abb144afeb37098142b8cf19a78e48b4e5f77b 100644 (file)
@@ -48,7 +48,7 @@ void ul_path_init_debug(void)
        __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));
 
@@ -61,8 +61,14 @@ struct path_cxt *ul_new_path(const char *dir)
        pc->dir_fd = -1;
 
        if (dir) {
-               pc->dir_path = strdup(dir);
-               if (!pc->dir_path)
+               int rc;
+               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;
        }
        return pc;