summaryrefslogtreecommitdiffstats
path: root/libavcodec/libxvidff.c
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-07-06 13:04:21 +0000
committerMåns Rullgård <mans@mansr.com>2010-07-06 13:04:21 +0000
commit25cbc8b46e1d4d17c4725b52bcb5cec4d832f894 (patch)
tree22145354c7d002d1ced435f1423a231500403ebe /libavcodec/libxvidff.c
parentd0b9b91b57a8baf87f87d0388497afe66b050973 (diff)
downloadffmpeg-streaming-25cbc8b46e1d4d17c4725b52bcb5cec4d832f894.zip
ffmpeg-streaming-25cbc8b46e1d4d17c4725b52bcb5cec4d832f894.tar.gz
Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
Originally committed as revision 24074 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/libxvidff.c')
-rw-r--r--libavcodec/libxvidff.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c
index 2c58e59..1314538 100644
--- a/libavcodec/libxvidff.c
+++ b/libavcodec/libxvidff.c
@@ -25,11 +25,17 @@
* @author Adam Thayer (krevnik@comcast.net)
*/
+/* needed for mkstemp() */
+#define _XOPEN_SOURCE 600
+
#include <xvid.h>
#include <unistd.h>
#include "avcodec.h"
#include "libavutil/intreadwrite.h"
#include "libxvid_internal.h"
+#if !HAVE_MKSTEMP
+#include <fcntl.h>
+#endif
/**
* Buffer management macros.
@@ -764,6 +770,42 @@ int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) {
}
}
+/* Wrapper to work around the lack of mkstemp() on mingw/cygin.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * @return file descriptor of opened file (or -1 on error)
+ * and opened file name in **filename. */
+int av_tempfile(char *prefix, char **filename) {
+ int fd=-1;
+#if !HAVE_MKSTEMP
+ *filename = tempnam(".", prefix);
+#else
+ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
+ *filename = av_malloc(len);
+#endif
+ /* -----common section-----*/
+ if (*filename == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
+ return -1;
+ }
+#if !HAVE_MKSTEMP
+ fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
+#else
+ snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+ if (fd < 0) {
+ snprintf(*filename, len, "./%sXXXXXX", prefix);
+ fd = mkstemp(*filename);
+ }
+#endif
+ /* -----common section-----*/
+ if (fd < 0) {
+ av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
+ return -1;
+ }
+ return fd; /* success */
+}
+
/**
* Xvid codec definition for libavcodec.
*/
OpenPOWER on IntegriCloud