]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: add lxc_make_tmpfile()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 18 Oct 2017 17:48:57 +0000 (19:48 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 21 Oct 2017 16:38:12 +0000 (18:38 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c
src/lxc/utils.h

index 4c886caddfe5d247d71f65a7966a5e82bc2d2f93..e4015bdc89a83b113b7c5d3739e560f51d413735 100644 (file)
@@ -2339,3 +2339,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;
+}
index 881a09d5d39eea0891c7953b5cb894a8d82431f4..32a181acca2e14869653d19ef17e377f93946abe 100644 (file)
@@ -466,5 +466,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 */