mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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
This commit is contained in:
parent
d0b9b91b57
commit
25cbc8b46e
@ -25,11 +25,17 @@
|
|||||||
* @author Adam Thayer (krevnik@comcast.net)
|
* @author Adam Thayer (krevnik@comcast.net)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* needed for mkstemp() */
|
||||||
|
#define _XOPEN_SOURCE 600
|
||||||
|
|
||||||
#include <xvid.h>
|
#include <xvid.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
#include "libxvid_internal.h"
|
#include "libxvid_internal.h"
|
||||||
|
#if !HAVE_MKSTEMP
|
||||||
|
#include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer management macros.
|
* 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.
|
* Xvid codec definition for libavcodec.
|
||||||
*/
|
*/
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
* utils.
|
* utils.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* needed for mkstemp() */
|
|
||||||
#define _XOPEN_SOURCE 600
|
|
||||||
|
|
||||||
#include "libavutil/avstring.h"
|
#include "libavutil/avstring.h"
|
||||||
#include "libavutil/integer.h"
|
#include "libavutil/integer.h"
|
||||||
#include "libavutil/crc.h"
|
#include "libavutil/crc.h"
|
||||||
@ -37,15 +34,11 @@
|
|||||||
#include "opt.h"
|
#include "opt.h"
|
||||||
#include "imgconvert.h"
|
#include "imgconvert.h"
|
||||||
#include "audioconvert.h"
|
#include "audioconvert.h"
|
||||||
#include "libxvid_internal.h"
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#if !HAVE_MKSTEMP
|
|
||||||
#include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int volatile entangled_thread_counter=0;
|
static int volatile entangled_thread_counter=0;
|
||||||
int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
|
int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
|
||||||
@ -1072,42 +1065,6 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
|
|||||||
return 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.
|
|
||||||
* @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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *abbr;
|
const char *abbr;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
Loading…
Reference in New Issue
Block a user