}
int open_tmpfile_unlinkable(const char *directory, int flags) {
- char *p;
- int fd, r;
+ int r;
if (!directory) {
r = tmp_dir(&directory);
/* Returns an unlinked temporary file that cannot be linked into the file system anymore */
/* Try O_TMPFILE first, if it is supported */
- fd = open(directory, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR);
+ int fd = open(directory, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR);
if (fd >= 0)
return fd;
/* Fall back to unguessable name + unlinking */
- p = strjoina(directory, "/systemd-tmp-XXXXXX");
+ _cleanup_free_ char *p = path_join(directory, "/systemd-tmp-XXXXXX");
+ if (!p)
+ return -ENOMEM;
fd = mkostemp_safe(p);
if (fd < 0)
}
int open_tmpfile_linkable_at(int dir_fd, const char *target, int flags, char **ret_path) {
- _cleanup_free_ char *tmp = NULL;
- int r, fd;
+ int r;
assert(target);
assert(ret_path);
* which case "ret_path" will be returned as NULL. If not possible the temporary path name used is returned in
* "ret_path". Use link_tmpfile() below to rename the result after writing the file in full. */
- fd = open_parent_at(dir_fd, target, O_TMPFILE|flags, 0640);
+ int fd = open_parent_at(dir_fd, target, O_TMPFILE|flags, 0640);
if (fd >= 0) {
*ret_path = NULL;
return fd;
log_debug_errno(fd, "Failed to use O_TMPFILE for %s: %m", target);
+ _cleanup_free_ char *tmp = NULL;
r = tempfn_random(target, NULL, &tmp);
if (r < 0)
return r;