sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* [WIP/PATCH] restart writes on EINTR
@ 2022-06-05 21:07 Eric Wong
  2022-06-10 19:05 ` Måns Rullgård
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2022-06-05 21:07 UTC (permalink / raw)
  To: sox-devel

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;


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-11  2:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 21:07 [WIP/PATCH] restart writes on EINTR Eric Wong
2022-06-10 19:05 ` Måns Rullgård
2022-06-11  2:17   ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).