file: properly forward errors from file_read() and file_write()

Message ID 20150903114004.144675DABC@aruru.libav.org
State New
Headers show

Commit Message

Janne Grunau Sept. 3, 2015, 11:40 a.m.
Module: libav
Branch: master
Commit: e05f7ed5436207f4a55f1978b223c7f8bc82af42

Author:    Sean McGovern <gseanmcg@gmail.com>
Committer: Luca Barbato <lu_zero@gentoo.org>
Date:      Thu Aug 27 00:04:15 2015 -0400

file: properly forward errors from file_read() and file_write()

Bug-Id: 881

CC: libav-stable@libav.org

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>

---

 libavformat/file.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch

diff --git a/libavformat/file.c b/libavformat/file.c
index 2837e9f..b54db9a 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -59,13 +59,15 @@  static const AVClass file_class = {
 static int file_read(URLContext *h, unsigned char *buf, int size)
 {
     FileContext *c = h->priv_data;
-    return read(c->fd, buf, size);
+    int ret = read(c->fd, buf, size);
+    return (ret == -1) ? AVERROR(errno) : ret;
 }
 
 static int file_write(URLContext *h, const unsigned char *buf, int size)
 {
     FileContext *c = h->priv_data;
-    return write(c->fd, buf, size);
+    int ret = write(c->fd, buf, size);
+    return (ret == -1) ? AVERROR(errno) : ret;
 }
 
 static int file_get_handle(URLContext *h)