summaryrefslogtreecommitdiff
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorCorey Hickey <bugfood-ml@fatooh.org>2006-03-30 04:33:05 +0000
committerCorey Hickey <bugfood-ml@fatooh.org>2006-03-30 04:33:05 +0000
commit1005f542b20cb152514c9496689148fc4456f438 (patch)
treeff65aadb3a063f6a1cd0f72c2bd4f3a38afc1bae /libavcodec/utils.c
parent06ab9cffb25518030a1434da5958a5c07f4a7cd3 (diff)
- Add new file internal.h for common internal-use-only functions.
- Add new function av_tempfile() for creating temporary files; contains workaround for MinGW. - Make XviD stuff use av_tempfile(). Originally committed as revision 5245 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 7e5d3b0372..3a26c6f94a 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -33,6 +33,9 @@
#include <stdarg.h>
#include <limits.h>
#include <float.h>
+#ifdef CONFIG_WIN32
+#include <fcntl.h>
+#endif
const uint8_t ff_reverse[256]={
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
@@ -1349,3 +1352,39 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
n++;
return n;
}
+
+/* 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.
+ * Returns 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;
+#ifdef CONFIG_WIN32
+ *filename = tempnam(".", prefix);
+#else
+ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
+ *filename = av_malloc(len * sizeof(char));
+#endif
+ /* -----common section-----*/
+ if (*filename == NULL) {
+ av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
+ return -1;
+ }
+#ifdef CONFIG_WIN32
+ 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 */
+}