1 #include "stdio_impl.h"
4 int __fseeko_unlocked(FILE *f, off_t off, int whence)
6 /* Fail immediately for invalid whence argument. */
7 if (whence != SEEK_CUR && whence != SEEK_SET && whence != SEEK_END) {
12 /* Adjust relative offset for unread data in buffer, if any. */
13 if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos;
15 /* Flush write buffer, and report error on failure. */
16 if (f->wpos != f->wbase) {
18 if (!f->wpos) return -1;
21 /* Leave writing mode */
22 f->wpos = f->wbase = f->wend = 0;
24 /* Perform the underlying seek. */
25 if (f->seek(f, off, whence) < 0) return -1;
27 /* If seek succeeded, file is seekable and we discard read buffer. */
28 f->rpos = f->rend = 0;
34 int __fseeko(FILE *f, off_t off, int whence)
38 result = __fseeko_unlocked(f, off, whence);
43 int fseek(FILE *f, long off, int whence)
45 return __fseeko(f, off, whence);
48 weak_alias(__fseeko, fseeko);
50 weak_alias(fseeko, fseeko64);