[PATCH 1/6] padsp: Fix flush

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



read() can return a number of bytes read less than k

CID 1137981
---
 src/utils/padsp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/utils/padsp.c b/src/utils/padsp.c
index 943479b..bb01f7f 100644
--- a/src/utils/padsp.c
+++ b/src/utils/padsp.c
@@ -1768,11 +1768,18 @@ static int dsp_flush_fd(int fd) {
     while (l > 0) {
         char buf[1024];
         size_t k;
+        ssize_t r;
 
         k = (size_t) l > sizeof(buf) ? sizeof(buf) : (size_t) l;
-        if (read(fd, buf, k) < 0)
+        r = read(fd, buf, k);
+        if (r < 0) {
+            if (errno == EAGAIN)
+                break;
             debug(DEBUG_LEVEL_NORMAL, __FILE__": read(): %s\n", strerror(errno));
-        l -= k;
+            return -1;
+        } else if (r == 0)
+            return 0;
+        l -= r;
     }
 
     return 0;
-- 
2.7.4



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux