[vlc-commits] posix: use VLC fallback if mkostemp() is missing

Rémi Denis-Courmont git at videolan.org
Sat Sep 21 11:49:07 CEST 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Sep 21 11:53:17 2019 +0300| [be67594c5d46c799f234a2cfaf03878d8dc72e1e] | committer: Rémi Denis-Courmont

posix: use VLC fallback if mkostemp() is missing

vlc_mkstemp() can open the temporary file with O_CLOEXEC, which
POSIX mkstemp() cannot do. So in this case, using the VLC
implementation avoids a bug.

This partially reverts 34d4f3135b0ed3594fbc9444083c7d68c930e0c7.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=be67594c5d46c799f234a2cfaf03878d8dc72e1e
---

 src/posix/filesystem.c | 11 +++--------
 src/text/filesystem.c  |  4 +---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index 0ba1a37957..e63a921d66 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -45,7 +45,7 @@
 #include <vlc_common.h>
 #include <vlc_fs.h>
 
-#if !defined(HAVE_ACCEPT4) || !defined HAVE_MKOSTEMP
+#if !defined(HAVE_ACCEPT4)
 static inline void vlc_cloexec(int fd)
 {
     fcntl(fd, F_SETFD, FD_CLOEXEC | fcntl(fd, F_GETFD));
@@ -86,17 +86,12 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
 #endif
 }
 
+#ifdef HAVE_MKOSTEMP
 int vlc_mkstemp (char *template)
 {
-#if defined (HAVE_MKOSTEMP)
     return mkostemp(template, O_CLOEXEC);
-#else
-    int fd = mkstemp(template);
-    if (fd != -1)
-        vlc_cloexec(fd);
-    return fd;
-#endif
 }
+#endif
 
 VLC_WEAK int vlc_memfd(void)
 {
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 950fcf3d0e..2f3b6470c8 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -199,10 +199,9 @@ int vlc_scandir( const char *dirname, char ***namelist,
     return val;
 }
 
-#if defined (_WIN32) || defined (__OS2__)
 # include <vlc_rand.h>
 
-int vlc_mkstemp( char *template )
+VLC_WEAK int vlc_mkstemp(char *template)
 {
     static const char bytes[] =
         "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqstruvwxyz_-";
@@ -243,4 +242,3 @@ int vlc_mkstemp( char *template )
     errno = EEXIST;
     return -1;
 }
-#endif



More information about the vlc-commits mailing list