correct locking in stdio functions that tried to be lock-free
[musl] / src / stdio / __toread.c
1 #include <stdio_impl.h>
2
3 int __toread(FILE *f)
4 {
5         f->mode |= f->mode-1;
6         if (f->wpos > f->buf) f->write(f, 0, 0);
7         f->wpos = f->wbase = f->wend = 0;
8         if (f->flags & (F_EOF|F_NORD)) {
9                 if (f->flags & F_NORD) f->flags |= F_ERR;
10                 return EOF;
11         }
12         f->rpos = f->rend = f->buf;
13         return 0;
14 }
15
16 static const int dummy = 0;
17 weak_alias(dummy, __towrite_used);
18
19 void __stdio_exit(void);
20
21 void __seek_on_exit()
22 {
23         if (!__towrite_used) __stdio_exit();
24 }