shithub: sox

Download patch

ref: e31bb3efb29f59735b983701370333e406e7c243
parent: 106014e37d0702acbffc4a8d6492823c5473ccf2
author: rrt <rrt>
date: Wed Dec 26 13:34:24 EST 2007

Put error checking back, but don't signal error for EOF unless 0 bytes
were returned.

--- a/src/misc.c
+++ b/src/misc.c
@@ -115,7 +115,8 @@
  */
 size_t sox_readbuf(sox_format_t * ft, void *buf, sox_size_t len)
 {
-  return fread(buf, 1, len, ft->fp);
+  size_t ret = fread(buf, 1, len, ft->fp);
+  return (ferror(ft->fp) || (feof(ft->fp) && ret == 0)) ? 0 : ret;
 }
 
 /* Skip input without seeking. */
@@ -147,7 +148,7 @@
 size_t sox_writebuf(sox_format_t * ft, void const *buf, sox_size_t len)
 {
   size_t ret = fwrite(buf, 1, len, ft->fp);
-  return (ferror(ft->fp) || feof(ft->fp)) ? 0 : ret;
+  return (ferror(ft->fp) || (feof(ft->fp) && ret == 0)) ? 0 : ret;
 }
 
 sox_size_t sox_filelength(sox_format_t * ft)