From: Franck Bui Date: Mon, 30 Jul 2018 13:10:49 +0000 (+0200) Subject: fileio: make tempfn_random_child() accept empty string as path X-Git-Tag: v240~864^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43231f00c2b9508c37d4cbbb2e49e9b99b096792;p=thirdparty%2Fsystemd.git fileio: make tempfn_random_child() accept empty string as path In this case it simply returns the random generated filename with anything prefixed. --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 20d3f567c9d..ea607f8cfb9 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++) {