Skip to content
Snippets Groups Projects
Commit 16e20657 authored by Lyndon Brown's avatar Lyndon Brown
Browse files

platform: avoid hard coded temp dir path in vlc_memfd()

on posix/linux the $TMPDIR path should be preferred, using "/tmp" as a
fallback. here we use our new config_GetTempPath() helper.
parent d48d7266
No related branches found
Tags 1.0.0-pre2
No related merge requests found
......@@ -33,6 +33,7 @@
#include <vlc_common.h>
#include <vlc_fs.h>
#include <vlc_configuration.h>
int vlc_memfd(void)
{
......@@ -43,16 +44,30 @@ int vlc_memfd(void)
return fd;
#endif
char *tempdir = config_GetTempPath();
if (tempdir == NULL)
return -1;
/* Fallback to open with O_TMPFILE, */
fd = open("/tmp", O_RDWR | O_CLOEXEC | O_TMPFILE, S_IRUSR | S_IWUSR);
if (fd != -1 || (errno != EISDIR && errno != EOPNOTSUPP))
fd = open(tempdir, O_RDWR | O_CLOEXEC | O_TMPFILE, S_IRUSR | S_IWUSR);
if (fd != -1 || (errno != EISDIR && errno != EOPNOTSUPP)) {
free(tempdir);
return fd;
}
/* Fallback to POSIX implementation if O_TMPFILE is not supported (errno is
* EISDIR, or EOPNOTSUPP, cf. man open(2). */
char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX";
const char *filetemplate = PACKAGE_NAME"XXXXXX";
char *bufpath;
if (asprintf(&bufpath, "%s/%s", tempdir, filetemplate) == -1) {
free(tempdir);
return -1;
}
free(tempdir);
fd = vlc_mkstemp(bufpath);
if (fd != -1)
unlink(bufpath);
free(bufpath);
return fd;
}
......@@ -44,6 +44,7 @@
#include <vlc_common.h>
#include <vlc_fs.h>
#include <vlc_configuration.h>
#if !defined(HAVE_ACCEPT4)
static inline void vlc_cloexec(int fd)
......@@ -90,12 +91,22 @@ int vlc_mkstemp (char *template)
VLC_WEAK int vlc_memfd(void)
{
char bufpath[] = "/tmp/"PACKAGE_NAME"XXXXXX";
int fd;
char *tempdir = config_GetTempPath();
if (tempdir == NULL)
return -1;
const char *filetemplate = PACKAGE_NAME"XXXXXX";
char *bufpath;
if (asprintf(&bufpath, "%s/%s", tempdir, filetemplate) == -1) {
free(tempdir);
return -1;
}
free(tempdir);
fd = vlc_mkstemp (bufpath);
int fd = vlc_mkstemp(bufpath);
if (fd != -1)
unlink (bufpath);
free(bufpath);
return fd;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment