|
|
1.1 root 1: /*
2: * Seek for standard library. Coordinates with buffering.
3: */
4:
5: #include <stdio.h>
6:
7: long lseek();
8:
9: fseek(iop, offset, ptrname)
10: FILE *iop;
11: long offset;
12: {
13: register resync, c;
14: long p;
15:
16: iop->_flag &= ~_IOEOF;
17: if (iop->_flag&_IOREAD) {
18: if (ptrname<2 && iop->_base &&
19: !(iop->_flag&_IONBF)) {
20: c = iop->_cnt;
21: p = offset;
22: if (ptrname==0)
23: p += c - lseek(fileno(iop),0L,1);
24: else
25: offset -= c;
26: if(c>0&&p<=c&&p>=iop->_base-iop->_ptr){
27: iop->_ptr += (int)p;
28: iop->_cnt -= (int)p;
29: return(0);
30: }
31: resync = offset&01;
32: } else
33: resync = 0;
34: p = lseek(fileno(iop), offset-resync, ptrname);
35: iop->_cnt = 0;
36: if (resync)
37: getc(iop);
38: }
39: else if (iop->_flag&_IOWRT) {
40: fflush(iop);
41: p = lseek(fileno(iop), offset, ptrname);
42: }
43: return(p==-1?-1:0);
44: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.