[FFmpeg-devel] [PATCH 2/2] lavf/file: Add support for file syncing.

Andrey Semashev andrey.semashev at gmail.com
Mon Dec 3 14:38:31 EET 2018


This commit adds support for IO synchronization API to the file backend.
---
 libavformat/file.c       | 10 ++++++++++
 libavformat/os_support.h |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/libavformat/file.c b/libavformat/file.c
index 1d321c4205..9765fd76c7 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -254,6 +254,15 @@ static int64_t file_seek(URLContext *h, int64_t pos, int whence)
     return ret < 0 ? AVERROR(errno) : ret;
 }
 
+static int file_sync(URLContext *h)
+{
+    if (h->flags & AVIO_FLAG_WRITE) {
+        FileContext *c = h->priv_data;
+        return fsync(c->fd);
+    }
+    return 0;
+}
+
 static int file_close(URLContext *h)
 {
     FileContext *c = h->priv_data;
@@ -353,6 +362,7 @@ const URLProtocol ff_file_protocol = {
     .url_close           = file_close,
     .url_get_file_handle = file_get_handle,
     .url_check           = file_check,
+    .url_sync            = file_sync,
     .url_delete          = file_delete,
     .url_move            = file_move,
     .priv_data_size      = sizeof(FileContext),
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 7a56dc9a7c..fcbdc884ba 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -93,6 +93,8 @@ static inline int is_dos_path(const char *path)
 #ifndef S_IWUSR
 #define S_IWUSR S_IWRITE
 #endif
+
+#define fsync _commit
 #endif
 
 #if CONFIG_NETWORK
-- 
2.19.1



More information about the ffmpeg-devel mailing list