1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-13 21:28:01 +02:00

libxvid: Require availability of mkstemp()

The replacement code uses tempnam(), which is dangerous.
Such a fringe feature is not worth the trouble.
This commit is contained in:
Diego Biurrun 2015-02-12 10:11:22 +01:00
parent a67ae67083
commit 12db2832e4
2 changed files with 3 additions and 16 deletions

2
configure vendored
View File

@ -2290,7 +2290,7 @@ libx262_encoder_deps="libx262"
libx264_encoder_deps="libx264" libx264_encoder_deps="libx264"
libx265_encoder_deps="libx265" libx265_encoder_deps="libx265"
libxavs_encoder_deps="libxavs" libxavs_encoder_deps="libxavs"
libxvid_encoder_deps="libxvid" libxvid_encoder_deps="libxvid mkstemp"
# demuxers / muxers # demuxers / muxers
ac3_demuxer_select="ac3_parser" ac3_demuxer_select="ac3_parser"

View File

@ -22,9 +22,7 @@
#include "config.h" #include "config.h"
#if !HAVE_MKSTEMP
#include <fcntl.h> #include <fcntl.h>
#endif
#include <unistd.h> #include <unistd.h>
#include <xvid.h> #include <xvid.h>
@ -35,36 +33,25 @@
#include "libxvid.h" #include "libxvid.h"
#include "mpegvideo.h" #include "mpegvideo.h"
/* Wrapper to work around the lack of mkstemp() on mingw. /* Create temporary file using mkstemp(), tries /tmp first, if possible.
* Also, tries to create file in /tmp first, if possible.
* *prefix can be a character constant; *filename will be allocated internally. * *prefix can be a character constant; *filename will be allocated internally.
* @return file descriptor of opened file (or -1 on error) * Return file descriptor of opened file (or error code on error)
* and opened file name in **filename. */ * and opened file name in **filename. */
int ff_tempfile(const char *prefix, char **filename) int ff_tempfile(const char *prefix, char **filename)
{ {
int fd = -1; int fd = -1;
#if !HAVE_MKSTEMP
*filename = tempnam(".", prefix);
#else
size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
*filename = av_malloc(len); *filename = av_malloc(len);
#endif
/* -----common section-----*/
if (!(*filename)) { if (!(*filename)) {
av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
#if !HAVE_MKSTEMP
fd = avpriv_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
#else
snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
fd = mkstemp(*filename); fd = mkstemp(*filename);
if (fd < 0) { if (fd < 0) {
snprintf(*filename, len, "./%sXXXXXX", prefix); snprintf(*filename, len, "./%sXXXXXX", prefix);
fd = mkstemp(*filename); fd = mkstemp(*filename);
} }
#endif
/* -----common section-----*/
if (fd < 0) { if (fd < 0) {
av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
return AVERROR(EIO); return AVERROR(EIO);