From: Denys Vlasenko <vda.linux@googlemail.com>
To: Rich Felker <dalias@libc.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>,
musl <musl@lists.openwall.com>
Subject: [PATCH] make fflush_unlocked(NULL) work
Date: Sun, 18 Sep 2016 21:44:55 +0200 [thread overview]
Message-ID: <20160918194455.21981-1-vda.linux@googlemail.com> (raw)
In glibc, fflush_unlocked(NULL) works.
Before this patch, musl was segfaulting.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
CC: musl <musl@lists.openwall.com>
---
src/stdio/fflush.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index 3f462c8..06d7a56 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -2,20 +2,35 @@
static int __fflush_unlocked(FILE *f)
{
- /* If writing, flush output */
- if (f->wpos > f->wbase) {
- f->write(f, 0, 0);
- if (!f->wpos) return EOF;
+ int r;
+
+ if (f) {
+ /* If writing, flush output */
+ if (f->wpos > f->wbase) {
+ f->write(f, 0, 0);
+ if (!f->wpos) return EOF;
+ }
+
+ /* If reading, sync position, per POSIX */
+ if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
+
+ /* Clear read and write modes */
+ f->wpos = f->wbase = f->wend = 0;
+ f->rpos = f->rend = 0;
+
+ return 0;
}
- /* If reading, sync position, per POSIX */
- if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
+ /* fflush_unlocked(NULL) is supported by glibc, mimic that */
- /* Clear read and write modes */
- f->wpos = f->wbase = f->wend = 0;
- f->rpos = f->rend = 0;
+ r = __stdout_used ? __fflush_unlocked(__stdout_used) : 0;
- return 0;
+ for (f=*__ofl_lock(); f; f=f->next) {
+ if (f->wpos > f->wbase) r |= __fflush_unlocked(f);
+ }
+ __ofl_unlock();
+
+ return r;
}
/* stdout.c will override this if linked */
--
2.9.2
next reply other threads:[~2016-09-18 19:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-18 19:44 Denys Vlasenko [this message]
2016-09-18 20:36 ` Rich Felker
2016-09-24 23:49 ` Denys Vlasenko
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160918194455.21981-1-vda.linux@googlemail.com \
--to=vda.linux@googlemail.com \
--cc=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).