[FFmpeg-devel] [PATCH 1/9] lavf: add AVIO_FLAG_EXCL flag system.
Nicolas George
george at nsup.org
Wed Apr 16 18:58:24 CEST 2014
TODO minor bump and APIChanges entry.
Signed-off-by: Nicolas George <george at nsup.org>
---
libavformat/avio.c | 12 +++++++++++-
libavformat/avio.h | 18 ++++++++++++++++++
libavformat/url.h | 1 +
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 4edaaa6..270c6d7 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -193,7 +193,17 @@ fail:
int ffurl_connect(URLContext *uc, AVDictionary **options)
{
- int err =
+ int err;
+
+ if ((uc->flags & AVIO_FLAG_EXCL) &&
+ !(uc->prot->flags & URL_PROTOCOL_FLAG_EXCL)) {
+ av_log(uc, AV_LOG_VERBOSE,
+ "Protocol %s does not support EXCL flag\n", uc->prot->name);
+ if ((uc->flags & AVIO_FLAG_EXCL_LOOSE) == AVIO_FLAG_EXCL ||
+ (uc->prot->url_check && uc->prot->url_check(uc, 0) >= 0))
+ return AVERROR(EEXIST);
+ }
+ err =
uc->prot->url_open2 ? uc->prot->url_open2(uc,
uc->filename,
uc->flags,
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 4004b6f..94d4c7b 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -375,6 +375,24 @@ int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
#define AVIO_FLAG_DIRECT 0x8000
/**
+ * Prevent overwriting existing files.
+ * If this flag is set, avio_open() will fail if the file already exists.
+ * It is roughly equivalent to the O_EXCL flag in the Unix/POSIX API.
+ * If the protocol does not support this feature reliably, assume the file
+ * exist and fail; see also AVIO_FLAG_EXCL_LOOSE.
+ */
+#define AVIO_FLAG_EXCL 0x10000
+
+/**
+ * Prevent overwriting existing files.
+ * If this flag is set, avio_open() will fail if the file already exists.
+ * It is roughly equivalent to the O_EXCL flag in the Unix/POSIX API.
+ * If the protocol does not support this feature reliably, perform an
+ * unreliable check using avio_check(); see also AVIO_FLAG_EXCL.
+ */
+#define AVIO_FLAG_EXCL_LOOSE 0x30000
+
+/**
* Create and initialize a AVIOContext for accessing the
* resource indicated by url.
* @note When the resource indicated by url has been opened in
diff --git a/libavformat/url.h b/libavformat/url.h
index 712ea0f..2aaedaa 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -33,6 +33,7 @@
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
#define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */
+#define URL_PROTOCOL_FLAG_EXCL 4 /*< AVIO_FLAG_EXCL is supported or irrelevant */
extern int (*url_interrupt_cb)(void);
--
1.7.10.4
More information about the ffmpeg-devel
mailing list