reduce spurious inclusion of libc.h
[musl] / src / stdio / fseek.c
1 #include "stdio_impl.h"
2 #include "libc.h"
3
4 int __fseeko_unlocked(FILE *f, off_t off, int whence)
5 {
6         /* Adjust relative offset for unread data in buffer, if any. */
7         if (whence == SEEK_CUR) off -= f->rend - f->rpos;
8
9         /* Flush write buffer, and report error on failure. */
10         if (f->wpos > f->wbase) {
11                 f->write(f, 0, 0);
12                 if (!f->wpos) return -1;
13         }
14
15         /* Leave writing mode */
16         f->wpos = f->wbase = f->wend = 0;
17
18         /* Perform the underlying seek. */
19         if (f->seek(f, off, whence) < 0) return -1;
20
21         /* If seek succeeded, file is seekable and we discard read buffer. */
22         f->rpos = f->rend = 0;
23         f->flags &= ~F_EOF;
24         
25         return 0;
26 }
27
28 int __fseeko(FILE *f, off_t off, int whence)
29 {
30         int result;
31         FLOCK(f);
32         result = __fseeko_unlocked(f, off, whence);
33         FUNLOCK(f);
34         return result;
35 }
36
37 int fseek(FILE *f, long off, int whence)
38 {
39         return __fseeko(f, off, whence);
40 }
41
42 weak_alias(__fseeko, fseeko);
43
44 LFS64(fseeko);