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