Eric Wong <normalper...@yhbt.net> writes:

> Only compile-tested, and I gotta run out for a bit and my not
> return alive.  I just noticed some EINTR errors while writing to
> pipes and haven't dealt with stdio or C in ages at this point.
>
> diff --git a/src/formats_i.c b/src/formats_i.c
> index 7048040d..d4082cc5 100644
> --- a/src/formats_i.c
> +++ b/src/formats_i.c
> @@ -129,10 +129,21 @@ int lsx_padbytes(sox_format_t * ft, size_t n)
>   */
>  size_t lsx_writebuf(sox_format_t * ft, void const * buf, size_t len)
>  {
> -  size_t ret = fwrite(buf, (size_t) 1, len, (FILE*)ft->fp);
> -  if (ret != len) {
> -    lsx_fail_errno(ft, errno, "error writing output file");
> -    clearerr((FILE*)ft->fp); /* Allows us to seek back to write header */
> +  FILE *fp = (FILE*)ft->fp;
> +  const char *c = (const char *)buf;
> +  size_t ret = fwrite(c, 1, len, fp);
> +
> +  while (ret != len) {
> +    switch (errno) {
> +    case EINTR:
> +      len -= ret;
> +      c += ret;
> +      ret = fwrite(c, 1, len, fp);
> +      break;
> +    default:
> +      lsx_fail_errno(ft, errno, "error writing output file");
> +      clearerr(fp); /* Allows us to seek back to write header */
> +    }
>    }
>    ft->tell_off += ret;
>    return ret;

The return value and ft->tell_off will be wrong in case the fwrite() was
restarted.

What did you do that caused the EINTR error?

-- 
Måns Rullgård


_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

Reply via email to