]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: make tempfn_random_child() accept empty string as path
authorFranck Bui <fbui@suse.com>
Mon, 30 Jul 2018 13:10:49 +0000 (15:10 +0200)
committerFranck Bui <fbui@suse.com>
Mon, 30 Jul 2018 13:54:03 +0000 (15:54 +0200)
In this case it simply returns the random generated filename with anything
prefixed.

src/basic/fileio.c

index 20d3f567c9d3fef8dc8f8f6e5efb57091296c354..ea607f8cfb94d12ae5907c306333368463bf4e4d 100644 (file)
@@ -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++) {