[libbluray-devel] file: flush output file when writing 0 bytes

hpi1 git at videolan.org
Sun May 15 15:44:39 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun May 15 16:06:49 2016 +0300| [c53481090eee920415c939de9c3a17a44d54c2aa] | committer: hpi1

file: flush output file when writing 0 bytes

Used to check for errors when writing files

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c53481090eee920415c939de9c3a17a44d54c2aa
---

 src/file/file_posix.c |    7 +++++++
 src/file/file_win32.c |    8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/file/file_posix.c b/src/file/file_posix.c
index 032e763..69cfcaa 100644
--- a/src/file/file_posix.c
+++ b/src/file/file_posix.c
@@ -110,6 +110,13 @@ static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size)
     ssize_t written, result;
 
     if (size <= 0 || size >= BD_MAX_SSIZE) {
+        if (size == 0) {
+            if (fsync((int)(intptr_t)file->internal)) {
+                BD_DEBUG(DBG_FILE, "fsync() failed (%p)\n", (void*)file);
+                return -1;
+            }
+            return 0;
+        }
         BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file);
         return 0;
     }
diff --git a/src/file/file_win32.c b/src/file/file_win32.c
index 6c9123f..d9845fb 100644
--- a/src/file/file_win32.c
+++ b/src/file/file_win32.c
@@ -91,6 +91,14 @@ static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size)
         return (int64_t)fwrite(buf, 1, (size_t)size, (FILE *)file->internal);
     }
 
+    if (size == 0) {
+        if (fflush((FILE *)file->internal)) {
+            BD_DEBUG(DBG_FILE, "fflush() failed (%p)\n", (void*)file);
+            return -1;
+        }
+        return 0;
+    }
+
     BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %"PRId64" (%p)\n", size, (void*)file);
     return 0;
 }



More information about the libbluray-devel mailing list