Skip to content

Commit

Permalink
utils: add lxc_make_tmpfile()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Nov 9, 2017
1 parent 785c692 commit 9360c59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lxc/utils.c
Expand Up @@ -2397,3 +2397,23 @@ bool lxc_nic_exists(char *nic)

return true;
}

int lxc_make_tmpfile(char *template, bool rm)
{
int fd, ret;

fd = mkstemp(template);
if (fd < 0)
return -1;

if (!rm)
return fd;

ret = unlink(template);
if (ret < 0) {
close(fd);
return -1;
}

return fd;
}
1 change: 1 addition & 0 deletions src/lxc/utils.h
Expand Up @@ -456,5 +456,6 @@ typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
extern bool has_fs_type(const char *path, fs_type_magic magic_val);
extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
extern bool lxc_nic_exists(char *nic);
extern int lxc_make_tmpfile(char *template, bool rm);

#endif /* __LXC_UTILS_H */

0 comments on commit 9360c59

Please sign in to comment.