Annotation of researchv9/libc/stdio/fseek.c, revision 1.1

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:        register FILE *iop;
        !            11:        long offset;
        !            12: {
        !            13:        register d;
        !            14:        register flag = iop->_flag;
        !            15:        register long p;
        !            16: 
        !            17:        iop->_flag &= ~_IOEOF;
        !            18:        if (flag & _IOWRT)
        !            19:                fflush(iop);
        !            20:        if (flag & _IORW)
        !            21:                iop->_flag &= ~(_IOWRT|_IOREAD);
        !            22:        if ((flag&_IOREAD) && iop->_base && ptrname!=2) do {
        !            23:                if (ptrname==1 && offset<=iop->_cnt &&
        !            24:                    offset>=iop->_base-iop->_ptr)
        !            25:                        d = offset;     
        !            26:                else {
        !            27:                        p = lseek(fileno(iop), 0L, 1);
        !            28:                        if (p < 0)
        !            29:                                break;
        !            30:                        d = iop->_cnt;
        !            31:                        if (ptrname == 1) {
        !            32:                                offset += p - d;
        !            33:                                ptrname = 0;
        !            34:                        }
        !            35:                        if (offset<0 || flag&_IORW)
        !            36:                                break;
        !            37:                        p -= offset;
        !            38:                        if (p >= 0 && p <= iop->_ptr - iop->_base + d)
        !            39:                                d -= (int)p;
        !            40:                        else {
        !            41:                                d = (unsigned int)offset % BUFSIZ;
        !            42:                                if (d == 0)     /* room for ungetc */
        !            43:                                        break;
        !            44:                                lseek(fileno(iop), offset - d, 0);
        !            45:                                if (_filbuf(iop) == EOF)
        !            46:                                        break;
        !            47:                                if (--d > iop->_cnt)    /* part buf */
        !            48:                                        break;
        !            49:                        }
        !            50:                }
        !            51:                iop->_cnt -= d;
        !            52:                iop->_ptr += d;
        !            53:                return (0);
        !            54:        } while (0);
        !            55:        if (flag & (_IORW|_IOREAD)) {
        !            56:                iop->_cnt = 0;
        !            57:                iop->_ptr = iop->_base;
        !            58:        }
        !            59:        return (lseek(fileno(iop), offset, ptrname) < 0? -1: 0);
        !            60: }

unix.superglobalmegacorp.com

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