Commit 34d4f313 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

filesystem: use native mkstemp() on POSIX

parent 75799939
...@@ -98,6 +98,20 @@ int vlc_openat (int dir, const char *filename, int flags, ...) ...@@ -98,6 +98,20 @@ int vlc_openat (int dir, const char *filename, int flags, ...)
return fd; 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 vlc_memfd (void)
{ {
int fd; int fd;
...@@ -115,16 +129,9 @@ int vlc_memfd (void) ...@@ -115,16 +129,9 @@ int vlc_memfd (void)
char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX"; char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX";
#ifdef HAVE_MKOSTEMP fd = vlc_mkstemp (bufpath);
fd = mkostemp (bufpath, O_CLOEXEC);
#else
fd = mkstemp (bufpath);
#endif
if (fd != -1) if (fd != -1)
{
fcntl (fd, F_SETFD, FD_CLOEXEC);
unlink (bufpath); unlink (bufpath);
}
return fd; return fd;
} }
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_fs.h> #include <vlc_fs.h>
#include <vlc_rand.h>
#include <assert.h> #include <assert.h>
...@@ -192,6 +191,9 @@ int vlc_scandir( const char *dirname, char ***namelist, ...@@ -192,6 +191,9 @@ int vlc_scandir( const char *dirname, char ***namelist,
return val; return val;
} }
#if defined (_WIN32) || defined (__OS2__)
# include <vlc_rand.h>
int vlc_mkstemp( char *template ) int vlc_mkstemp( char *template )
{ {
static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
...@@ -231,3 +233,4 @@ int vlc_mkstemp( char *template ) ...@@ -231,3 +233,4 @@ int vlc_mkstemp( char *template )
errno = EEXIST; errno = EEXIST;
return -1; return -1;
} }
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment