Permalink
Browse files

fileio: make tempfn_random_child() accept empty string as path

In this case it simply returns the random generated filename with anything
prefixed.
  • Loading branch information...
fbuihuu committed Jul 30, 2018
1 parent a2fc2f8 commit 43231f00c2b9508c37d4cbbb2e49e9b99b096792
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/basic/fileio.c
@@ -1319,16 +1319,18 @@ 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);

t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1);
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++) {

0 comments on commit 43231f0

Please sign in to comment.