X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Ffseek.c;h=8d9da4408fbfe22ed5cef60c7c05354e53e40adb;hp=bfaad375ddd55cc9ff3a13ad359da5ca017d78e2;hb=e3cd6c5c265cd481db6e0c5b529855d99f0bda30;hpb=ea343364a719add2cd8adf8a50c15bb5f9400dd8 diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c index bfaad375..8d9da440 100644 --- a/src/stdio/fseek.c +++ b/src/stdio/fseek.c @@ -5,17 +5,25 @@ int __fseeko_unlocked(FILE *f, off_t off, int whence) /* Adjust relative offset for unread data in buffer, if any. */ if (whence == SEEK_CUR) off -= f->rend - f->rpos; - /* If writing, flush output. */ - if (f->wpos > f->buf && __oflow(f)) return -1; + /* Flush write buffer, and report error on failure. */ + if (f->wpos > f->wbase) { + f->write(f, 0, 0); + if (!f->wpos) return -1; + } - /* Perform the underlying seek operation. */ - if (f->seek(f, off, whence) < 0) return -1; + /* Leave writing mode */ + f->wpos = f->wbase = f->wend = 0; + + /* Perform the underlying seek. */ + if (f->seek(f, off, whence) < 0) { + f->flags |= F_ERR; + return -1; + } /* If seek succeeded, file is seekable and we discard read buffer. */ - f->rpos = f->rend = f->rstop = 0; + f->rpos = f->rend = 0; f->flags &= ~F_EOF; - FUNLOCK(f); return 0; }