remove flush hook cruft that was never used from stdio
[musl] / src / stdio / fflush.c
1 #include "stdio_impl.h"
2
3 static int __fflush_unlocked(FILE *f)
4 {
5         /* If writing, flush output */
6         if (f->wpos > f->wbase) {
7                 f->write(f, 0, 0);
8                 if (!f->wpos) return EOF;
9         }
10
11         /* If reading, sync position, per POSIX */
12         if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR);
13
14         /* Clear read and write modes */
15         f->wpos = f->wbase = f->wend = 0;
16         f->rpos = f->rend = 0;
17
18         return 0;
19 }
20
21 /* stdout.c will override this if linked */
22 static FILE *const dummy = 0;
23 weak_alias(dummy, __stdout_used);
24
25 int fflush(FILE *f)
26 {
27         int r;
28         FILE *next;
29
30         if (f) {
31                 FLOCK(f);
32                 r = __fflush_unlocked(f);
33                 FUNLOCK(f);
34                 return r;
35         }
36
37         r = __stdout_used ? fflush(__stdout_used) : 0;
38
39         OFLLOCK();
40         for (f=libc.ofl_head; f; f=next) {
41                 FLOCK(f);
42                 //OFLUNLOCK();
43                 if (f->wpos > f->wbase) r |= __fflush_unlocked(f);
44                 //OFLLOCK();
45                 next = f->next;
46                 FUNLOCK(f);
47         }
48         OFLUNLOCK();
49         
50         return r;
51 }
52
53 weak_alias(__fflush_unlocked, fflush_unlocked);