X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffseek.c;h=439308f7574ba7efbd03ea9626c9041f3b7a322c;hb=c24a9923863fc29af4a5249727fe800224fc3c44;hp=bfaad375ddd55cc9ff3a13ad359da5ca017d78e2;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c index bfaad375..439308f7 100644 --- a/src/stdio/fseek.c +++ b/src/stdio/fseek.c @@ -3,19 +3,24 @@ 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 (whence == SEEK_CUR && f->rend) 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. */ + /* Leave writing mode */ + f->wpos = f->wbase = f->wend = 0; + + /* Perform the underlying seek. */ if (f->seek(f, off, whence) < 0) 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; } @@ -35,4 +40,4 @@ int fseek(FILE *f, long off, int whence) weak_alias(__fseeko, fseeko); -LFS64(fseeko); +weak_alias(fseeko, fseeko64);