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