From 43231f00c2b9508c37d4cbbb2e49e9b99b096792 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 30 Jul 2018 15:10:49 +0200 Subject: [PATCH] fileio: make tempfn_random_child() accept empty string as path In this case it simply returns the random generated filename with anything prefixed. --- src/basic/fileio.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 20d3f567c9..ea607f8cfb 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1319,8 +1319,7 @@ int tempfn_random_child(const char *p, const char *extra, char **ret) { r = tmp_dir(&p); if (r < 0) return r; - } else if (isempty(p)) - return -EINVAL; + } extra = strempty(extra); @@ -1328,7 +1327,10 @@ int tempfn_random_child(const char *p, const char *extra, char **ret) { if (!t) return -ENOMEM; - x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra); + if (isempty(p)) + x = stpcpy(stpcpy(t, ".#"), extra); + else + x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra); u = random_u64(); for (i = 0; i < 16; i++) {