Add one copy of the function into each of the libraries, similarly
to what we do for log2_tab. When using static libs, only one
copy of the file_open.o object file gets included, while when
using shared libraries, each of them get a copy of its own.
This fixes DLL builds with a statically linked C runtime, where
each DLL effectively has got its own instance of the C runtime,
where file descriptors can't be shared across runtimes.
---
libavcodec/Makefile | 1 +
libavcodec/file_open.c | 1 +
libavcodec/libxvid_rc.c | 2 +-
libavdevice/Makefile | 1 +
libavdevice/bktr.c | 4 ++--
libavdevice/dv1394.c | 2 +-
libavdevice/fbdev.c | 2 +-
libavdevice/file_open.c | 1 +
libavdevice/oss_audio.c | 4 ++--
libavdevice/v4l2.c | 2 +-
libavformat/Makefile | 1 +
libavformat/file.c | 2 +-
libavformat/file_open.c | 1 +
libavutil/file.c | 2 +-
libavutil/file_open.c | 2 +-
libavutil/internal.h | 2 +-
libavutil/random_seed.c | 2 +-
17 files changed, 19 insertions(+), 13 deletions(-)
create mode 100644 libavcodec/file_open.c
create mode 100644 libavdevice/file_open.c
create mode 100644 libavformat/file_open.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fc1bfb2..7ce7bea 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -17,6 +17,7 @@ OBJS = allcodecs.o
\
bitstream.o \
bitstream_filter.o \
codec_desc.o \
+ file_open.o \
fmtconvert.o \
imgconvert.o \
log2_tab.o \
diff --git a/libavcodec/file_open.c b/libavcodec/file_open.c
new file mode 100644
index 0000000..494a5d3
--- /dev/null
+++ b/libavcodec/file_open.c
@@ -0,0 +1 @@
+#include "libavutil/file_open.c"
diff --git a/libavcodec/libxvid_rc.c b/libavcodec/libxvid_rc.c
index 7f4a89d..c111f5b 100644
--- a/libavcodec/libxvid_rc.c
+++ b/libavcodec/libxvid_rc.c
@@ -55,7 +55,7 @@ int ff_tempfile(const char *prefix, char **filename) {
return -1;
}
#if !HAVE_MKSTEMP
- fd = avpriv_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
+ fd = ff_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
#else
snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
fd = mkstemp(*filename);
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 76d11c1..790a35a 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -6,6 +6,7 @@ HEADERS = avdevice.h
\
OBJS = alldevices.o \
avdevice.o \
+ file_open.o \
# input/output devices
OBJS-$(CONFIG_ALSA_INDEV) += alsa-audio-common.o \
diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index 06f4d86..e0f76bb 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -137,11 +137,11 @@ static av_cold int bktr_init(const char *video_device,
int width, int height,
act.sa_handler = catchsignal;
sigaction(SIGUSR1, &act, &old);
- *tuner_fd = avpriv_open("/dev/tuner0", O_RDONLY);
+ *tuner_fd = ff_open("/dev/tuner0", O_RDONLY);
if (*tuner_fd < 0)
av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing:
%s\n", strerror(errno));
- *video_fd = avpriv_open(video_device, O_RDONLY);
+ *video_fd = ff_open(video_device, O_RDONLY);
if (*video_fd < 0) {
av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno));
return -1;
diff --git a/libavdevice/dv1394.c b/libavdevice/dv1394.c
index d259e1a..a41cf14 100644
--- a/libavdevice/dv1394.c
+++ b/libavdevice/dv1394.c
@@ -89,7 +89,7 @@ static int dv1394_read_header(AVFormatContext * context)
goto failed;
/* Open and initialize DV1394 device */
- dv->fd = avpriv_open(context->filename, O_RDONLY);
+ dv->fd = ff_open(context->filename, O_RDONLY);
if (dv->fd < 0) {
av_log(context, AV_LOG_ERROR, "Failed to open DV interface: %s\n",
strerror(errno));
goto failed;
diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c
index 22c53a3..9d7ceeb 100644
--- a/libavdevice/fbdev.c
+++ b/libavdevice/fbdev.c
@@ -115,7 +115,7 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx)
if (avctx->flags & AVFMT_FLAG_NONBLOCK)
flags |= O_NONBLOCK;
- if ((fbdev->fd = avpriv_open(avctx->filename, flags)) == -1) {
+ if ((fbdev->fd = ff_open(avctx->filename, flags)) == -1) {
ret = AVERROR(errno);
av_log(avctx, AV_LOG_ERROR,
"Could not open framebuffer device '%s': %s\n",
diff --git a/libavdevice/file_open.c b/libavdevice/file_open.c
new file mode 100644
index 0000000..494a5d3
--- /dev/null
+++ b/libavdevice/file_open.c
@@ -0,0 +1 @@
+#include "libavutil/file_open.c"
diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c
index f1cc91f..add746c 100644
--- a/libavdevice/oss_audio.c
+++ b/libavdevice/oss_audio.c
@@ -64,9 +64,9 @@ static int audio_open(AVFormatContext *s1, int is_output,
const char *audio_devi
char *flip = getenv("AUDIO_FLIP_LEFT");
if (is_output)
- audio_fd = avpriv_open(audio_device, O_WRONLY);
+ audio_fd = ff_open(audio_device, O_WRONLY);
else
- audio_fd = avpriv_open(audio_device, O_RDONLY);
+ audio_fd = ff_open(audio_device, O_RDONLY);
if (audio_fd < 0) {
av_log(s1, AV_LOG_ERROR, "%s: %s\n", audio_device, strerror(errno));
return AVERROR(EIO);
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index adb289d..a6dfa15 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -124,7 +124,7 @@ static int device_open(AVFormatContext *ctx)
flags |= O_NONBLOCK;
}
- fd = avpriv_open(ctx->filename, flags);
+ fd = ff_open(ctx->filename, flags);
if (fd < 0) {
err = errno;
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5e2dd2a..64cc455 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -9,6 +9,7 @@ OBJS = allformats.o \
avio.o \
aviobuf.o \
cutils.o \
+ file_open.o \
format.o \
id3v1.o \
id3v2.o \
diff --git a/libavformat/file.c b/libavformat/file.c
index 2837e9f..0e142eb 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -111,7 +111,7 @@ static int file_open(URLContext *h, const char *filename,
int flags)
#ifdef O_BINARY
access |= O_BINARY;
#endif
- fd = avpriv_open(filename, access, 0666);
+ fd = ff_open(filename, access, 0666);
if (fd == -1)
return AVERROR(errno);
c->fd = fd;
diff --git a/libavformat/file_open.c b/libavformat/file_open.c
new file mode 100644
index 0000000..494a5d3
--- /dev/null
+++ b/libavformat/file_open.c
@@ -0,0 +1 @@
+#include "libavutil/file_open.c"
diff --git a/libavutil/file.c b/libavutil/file.c
index d2765b8..832c16a 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -50,7 +50,7 @@ int av_file_map(const char *filename, uint8_t **bufptr,
size_t *size,
int log_offset, void *log_ctx)
{
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
- int err, fd = avpriv_open(filename, O_RDONLY);
+ int err, fd = ff_open(filename, O_RDONLY);
struct stat st;
av_unused void *ptr;
off_t off_size;
diff --git a/libavutil/file_open.c b/libavutil/file_open.c
index 765eb60..3f756ad 100644
--- a/libavutil/file_open.c
+++ b/libavutil/file_open.c
@@ -68,7 +68,7 @@ fallback:
#define open win32_open
#endif
-int avpriv_open(const char *filename, int flags, ...)
+int ff_open(const char *filename, int flags, ...)
{
int fd;
unsigned int mode = 0;
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 355a42a..42c3258 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -199,6 +199,6 @@ void avpriv_request_sample(void *avc,
/**
* A wrapper for open() setting O_CLOEXEC.
*/
-int avpriv_open(const char *filename, int flags, ...);
+int ff_open(const char *filename, int flags, ...);
#endif /* AVUTIL_INTERNAL_H */
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 4680081..03a8a4c 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -37,7 +37,7 @@
static int read_random(uint32_t *dst, const char *file)
{
#if HAVE_UNISTD_H
- int fd = avpriv_open(file, O_RDONLY);
+ int fd = ff_open(file, O_RDONLY);
int err = -1;
if (fd == -1)
--
1.7.9.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel