utils: add lxc_make_tmpfile()

parent 785c692d
......@@ -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;
}
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment