major stdio overhaul, using readv/writev, plus other changes
[musl] / src / stdio / fseek.c
index bfaad37..8d9da44 100644 (file)
@@ -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;
 
        /* 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. */
 
        /* 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;
        
        f->flags &= ~F_EOF;
        
-       FUNLOCK(f);     
        return 0;
 }
 
        return 0;
 }