[alsa-devel] [TINYCOMPRESS][PATCH v3 5/7] compress.c: fix check for errors from poll(), read() and write()
Qais Yousef
qais.yousef at imgtec.com
Tue May 5 12:21:09 CEST 2015
When these functions fail they return -1 and set errno. Fix error checks
accordingly.
Signed-off-by: Qais Yousef <qais.yousef at imgtec.com>
---
src/lib/compress.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/lib/compress.c b/src/lib/compress.c
index 15dfdb74137e..84738d24ff45 100644
--- a/src/lib/compress.c
+++ b/src/lib/compress.c
@@ -383,7 +383,7 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
}
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop writing */
- if ((ret == 0) || (ret == -EBADFD))
+ if ((ret == 0) || (ret < 0 && errno == EBADFD))
break;
if (ret < 0)
return oops(compress, errno, "poll error");
@@ -397,11 +397,12 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
else
to_write = size;
written = write(compress->fd, cbuf, to_write);
- /* If play was paused the write returns -EBADFD */
- if (written == -EBADFD)
- break;
- if (written < 0)
+ if (written < 0) {
+ /* If play was paused the write returns -EBADFD */
+ if (errno == EBADFD)
+ break;
return oops(compress, errno, "write failed!");
+ }
size -= written;
cbuf += written;
@@ -443,7 +444,7 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
}
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop reading */
- if ((ret == 0) || (ret == -EBADFD))
+ if ((ret == 0) || (ret < 0 && errno == EBADFD))
break;
if (ret < 0)
return oops(compress, errno, "poll error");
@@ -457,11 +458,12 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
else
to_read = size;
num_read = read(compress->fd, cbuf, to_read);
- /* If play was paused the read returns -EBADFD */
- if (num_read == -EBADFD)
- break;
- if (num_read < 0)
+ if (num_read < 0) {
+ /* If play was paused the read returns -EBADFD */
+ if (errno == EBADFD)
+ break;
return oops(compress, errno, "read failed!");
+ }
size -= num_read;
cbuf += num_read;
--
2.1.0
More information about the Alsa-devel
mailing list