From 1cdb2692fbfca71c0b0f3302f522f6dc1f460664 Mon Sep 17 00:00:00 2001 From: Zefram Date: Tue, 19 Dec 2017 19:00:07 +0000 Subject: Perl_my_mkstemp_cloexec() function Like the other "_cloexec" I/O functions, this guarantees to return a file descriptor with FD_CLOEXEC set, and will set the flag atomically if possible. --- doio.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'doio.c') diff --git a/doio.c b/doio.c index 56615cdd90..d18e335a04 100644 --- a/doio.c +++ b/doio.c @@ -61,7 +61,7 @@ #include void -Perl_setfd_cloexec(pTHX_ int fd) +Perl_setfd_cloexec(int fd) { assert(fd >= 0); #if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC) @@ -70,7 +70,7 @@ Perl_setfd_cloexec(pTHX_ int fd) } void -Perl_setfd_inhexec(pTHX_ int fd) +Perl_setfd_inhexec(int fd) { assert(fd >= 0); #if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC) @@ -221,6 +221,19 @@ Perl_PerlLIO_open3_cloexec(pTHX_ const char *file, int flag, int perm) #endif } +int +Perl_my_mkstemp_cloexec(char *templte) +{ + PERL_ARGS_ASSERT_MY_MKSTEMP_CLOEXEC; +#if defined(O_CLOEXEC) + DO_ONEOPEN_EXPERIMENTING_CLOEXEC( + Perl_my_mkostemp(templte, O_CLOEXEC), + Perl_my_mkstemp(templte)); +#else + DO_ONEOPEN_THEN_CLOEXEC(Perl_my_mkstemp(templte)); +#endif +} + #ifdef HAS_PIPE int Perl_PerlProc_pipe_cloexec(pTHX_ int *pipefd) -- cgit v1.2.1