- /* 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;
+ }