Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Unified Diff: fusl/src/stdio/fflush.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/stdio/ferror.c ('k') | fusl/src/stdio/fgetc.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/stdio/fflush.c
diff --git a/fusl/src/stdio/fflush.c b/fusl/src/stdio/fflush.c
new file mode 100644
index 0000000000000000000000000000000000000000..3f462c80e8d12f6efbecd144a144d430736ec6eb
--- /dev/null
+++ b/fusl/src/stdio/fflush.c
@@ -0,0 +1,48 @@
+#include "stdio_impl.h"
+
+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;
+ }
+
+ /* 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;
+}
+
+/* stdout.c will override this if linked */
+static FILE *volatile dummy = 0;
+weak_alias(dummy, __stdout_used);
+
+int fflush(FILE *f)
+{
+ int r;
+
+ if (f) {
+ FLOCK(f);
+ r = __fflush_unlocked(f);
+ FUNLOCK(f);
+ return r;
+ }
+
+ r = __stdout_used ? fflush(__stdout_used) : 0;
+
+ for (f=*__ofl_lock(); f; f=f->next) {
+ FLOCK(f);
+ if (f->wpos > f->wbase) r |= __fflush_unlocked(f);
+ FUNLOCK(f);
+ }
+ __ofl_unlock();
+
+ return r;
+}
+
+weak_alias(__fflush_unlocked, fflush_unlocked);
« no previous file with comments | « fusl/src/stdio/ferror.c ('k') | fusl/src/stdio/fgetc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698