Annotation of 3BSD/lib/libNS/fseek.c, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1979 Regents of the University of California */
                      2: #include       <stdio.h>
                      3: 
                      4: /*
                      5:  * Seek for standard library.  Coordinates with buffering.
                      6:  */
                      7: 
                      8: long fseek(iop, offset, ptrname)
                      9: register FILE *iop;
                     10: long offset;
                     11: {
                     12:        register n, resync;
                     13: 
                     14:        if (iop->_flag&_IODIRT) {
                     15:                fflush(iop);
                     16:                return(lseek(fileno(iop), offset, ptrname));
                     17:        }
                     18:        if (iop->_flag&(_IOREAD|_IOWRT)) {
                     19:                resync = 0;
                     20:                if (ptrname==1) {       /* relative */
                     21:                        n = iop->_cnt;
                     22:                        if (n<0)
                     23:                                n = 0;
                     24:                } else {
                     25:                        n = offset&01;
                     26:                        resync = n;
                     27:                }
                     28:                n = lseek(fileno(iop), offset - n, ptrname);
                     29:                iop->_cnt = 0;
                     30:                iop->_ptr = iop->_base ;
                     31:                iop->_delta = 0;
                     32:                if (resync)
                     33:                        getc(iop);
                     34:                return(n);
                     35:        }
                     36:        _error("fseek\n");
                     37: }
                     38: 
                     39: /*  The current character is always iop->_cnt characters behind the current 
                     40: position in the file, except when a file is open and in use for pure writing
                     41: in which case it is _IODIRT(y), and will be correctly positioned by fflush */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.