[vlc-commits] filesystem: use native mkstemp() on POSIX
Rémi Denis-Courmont
git at videolan.org
Mon Aug 24 20:14:07 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 24 20:48:02 2015 +0300| [34d4f3135b0ed3594fbc9444083c7d68c930e0c7] | committer: Rémi Denis-Courmont
filesystem: use native mkstemp() on POSIX
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=34d4f3135b0ed3594fbc9444083c7d68c930e0c7
---
src/posix/filesystem.c | 23 +++++++++++++++--------
src/text/filesystem.c | 5 ++++-
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index bab9e85..9cf6876 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -98,6 +98,20 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
return fd;
}
+int vlc_mkstemp (char *template)
+{
+ int fd;
+
+#ifdef HAVE_MKOSTEMP
+ fd = mkostemp (template, O_CLOEXEC);
+#else
+ fd = mkstemp (template);
+#endif
+ if (fd != -1)
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
+ return fd;
+}
+
int vlc_memfd (void)
{
int fd;
@@ -115,16 +129,9 @@ int vlc_memfd (void)
char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX";
-#ifdef HAVE_MKOSTEMP
- fd = mkostemp (bufpath, O_CLOEXEC);
-#else
- fd = mkstemp (bufpath);
-#endif
+ fd = vlc_mkstemp (bufpath);
if (fd != -1)
- {
- fcntl (fd, F_SETFD, FD_CLOEXEC);
unlink (bufpath);
- }
return fd;
}
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index 4b4d0bb..3813896 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -30,7 +30,6 @@
#include <vlc_common.h>
#include <vlc_fs.h>
-#include <vlc_rand.h>
#include <assert.h>
@@ -192,6 +191,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 )
{
static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -231,3 +233,4 @@ int vlc_mkstemp( char *template )
errno = EEXIST;
return -1;
}
+#endif
More information about the vlc-commits
mailing list