]> 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>
Thu, 9 Nov 2017 00:03:58 +0000 (01:03 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c
src/lxc/utils.h

index 798209dacd8a36011d12d4a411e8eba10882803f..102bcdcfd763c96bea7c354f5179f61ac0e27cbd 100644 (file)
@@ -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;
+}
index a17e267858d863cb354ec9fd5af65ce9a6bc7807..967744ff3e5ad59b0e23dd13cc16dc1c1fd916a2 100644 (file)
@@ -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 */