mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
tmpfile-util: Introduce mkdtemp_open()
This commit is contained in:
parent
2fa6574e83
commit
86e69a44b4
@ -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;
|
||||
}
|
||||
|
@ -19,3 +19,4 @@ int link_tmpfile(int fd, const char *path, const char *target);
|
||||
int flink_tmpfile(FILE *f, const char *path, const char *target);
|
||||
|
||||
int mkdtemp_malloc(const char *template, char **ret);
|
||||
int mkdtemp_open(const char *template, int flags, char **ret);
|
||||
|
Loading…
x
Reference in New Issue
Block a user