|
|
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: #include "stdio.int.h" ! 11: ! 12: int ! 13: fseek(stream, offset, whence) register FILE *stream; long offset; int whence; ! 14: { ! 15: register _FILE2 *f2p; ! 16: ! 17: f2p = stream->_f2p; ! 18: ! 19: /* Adjust offset for ungotten character if necessary. */ ! 20: if ((whence == SEEK_CUR) && (stream->_ff2 & _FUNGOT)) ! 21: offset--; ! 22: ! 23: /* Ensure buffer is clean. */ ! 24: if (_fpseek(stream)==EOF) ! 25: return EOF; ! 26: ! 27: /* Perform the seek. */ ! 28: if ((offset=lseek(fileno(stream), offset, whence)) == -1L) ! 29: return EOF; ! 30: ! 31: /* Reset buffer pointers if necessary. */ ! 32: if (f2p->_bp != NULL) ! 33: f2p->_dp = stream->_cp = f2p->_bp + (unsigned)offset%(unsigned)(f2p->_ep - f2p->_bp); ! 34: ! 35: /* If the file was opened for append, force seek to end on write. */ ! 36: if ((stream->_ff2 & _FAPPND) && (offset != 0L || whence == SEEK_SET)) ! 37: f2p->_pt = &_fputa; ! 38: ! 39: /* Clear EOF flag. */ ! 40: stream->_ff1 &= ~_FEOF; ! 41: ! 42: return 0; ! 43: } ! 44: ! 45: /* 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.