fileio: make tempfn_random_child() accept empty string as path

In this case it simply returns the random generated filename with anything
prefixed.
This commit is contained in:
Franck Bui 2018-07-30 15:10:49 +02:00
parent a2fc2f8dd3
commit 43231f00c2
1 changed files with 5 additions and 3 deletions

View 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++) {