From: Christian Brauner Date: Wed, 18 Oct 2017 17:48:57 +0000 (+0200) Subject: utils: add lxc_make_tmpfile() X-Git-Tag: lxc-3.0.0.beta1~210^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=127c6e703b0a10b68aef44e8951b0507d72efd90;p=thirdparty%2Flxc.git utils: add lxc_make_tmpfile() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 4c886cadd..e4015bdc8 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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; +} diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 881a09d5d..32a181acc 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -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 */