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

index e6a44a516156d61049a0e5ab528ba7744b91e15e..501f74d3a93650c773c0ef03cb1225b92469f8a2 100644 (file)
@@ -2400,3 +2400,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 4aa21cdd457bbcf8bdccfdd9dc7e900816599d67..27428e15767d307f1fce624d47ba824fc0ed060f 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 */