|
|
1.1 ! root 1: /* ! 2: * libc/stdio/fseek.c ! 3: * ANSI-compliant C standard i/o library. ! 4: * fseek() ! 5: * ANSI 4.9.9.2. ! 6: * Seek to offset from whence in stream. ! 7: */ ! 8: ! 9: #include <stdio.h> ! 10: ! 11: int ! 12: fseek(stream, offset, whence) register FILE *stream; long offset; int whence; ! 13: { ! 14: register _FILE2 *f2p; ! 15: ! 16: f2p = stream->_f2p; ! 17: ! 18: /* Adjust offset for ungotten character if necessary. */ ! 19: if ((whence == SEEK_CUR) && (stream->_ff2 & _FUNGOT)) ! 20: offset--; ! 21: ! 22: /* Ensure buffer is clean. */ ! 23: if (_fpseek(stream)==EOF) ! 24: return EOF; ! 25: ! 26: /* Perform the seek. */ ! 27: if ((offset=lseek(fileno(stream), offset, whence)) == -1L) ! 28: return EOF; ! 29: ! 30: /* Reset buffer pointers if necessary. */ ! 31: if (f2p->_bp != NULL) ! 32: f2p->_dp = stream->_cp = f2p->_bp + (unsigned)offset%(unsigned)(f2p->_ep - f2p->_bp); ! 33: ! 34: /* If the file was opened for append, force seek to end on write. */ ! 35: if ((stream->_ff2 & _FAPPND) && (offset != 0L || whence == SEEK_SET)) ! 36: f2p->_pt = &_fputa; ! 37: ! 38: /* Clear EOF flag. */ ! 39: stream->_ff1 &= ~_FEOF; ! 40: ! 41: return 0; ! 42: } ! 43: ! 44: /* end of libc/stdio/fseek.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.