From: Eric Wong <normalperson@yhbt.net>
To: sox-devel@lists.sourceforge.net
Subject: [WIP/PATCH] restart writes on EINTR
Date: Sun, 5 Jun 2022 21:07:27 +0000 [thread overview]
Message-ID: <20220605210727.GA9582@dcvr> (raw)
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
next reply other threads:[~2022-06-05 21:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-05 21:07 Eric Wong [this message]
2022-06-10 19:05 ` [WIP/PATCH] restart writes on EINTR Måns Rullgård
2022-06-11 2:17 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.sourceforge.net/lists/listinfo/sox-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220605210727.GA9582@dcvr \
--to=sox-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).