tmpfile-util: Introduce mkdtemp_open()

This commit is contained in:
Daan De Meyer
2022-11-09 11:13:58 +01:00
parent 2fa6574e83
commit 86e69a44b4
2 changed files with 21 additions and 0 deletions
+20
View File
@@ -358,3 +358,23 @@ int mkdtemp_malloc(const char *template, char **ret) {
*ret = TAKE_PTR(p);
return 0;
}
int mkdtemp_open(const char *template, int flags, char **ret) {
_cleanup_free_ char *p = NULL;
int fd, r;
r = mkdtemp_malloc(template, &p);
if (r < 0)
return r;
fd = RET_NERRNO(open(p, O_DIRECTORY|O_CLOEXEC|flags));
if (fd < 0) {
(void) rmdir(p);
return fd;
}
if (ret)
*ret = TAKE_PTR(p);
return fd;
}