# /* Seek for standard library. Coordinates with buffering. * * The new position is at the signed distance 'offset' bytes from the beginning, * the current position, or the end of the file, according as 'ptrname' has * the value 0, 1, or 2. */ #include "stdio.h" #define BLKSIZ 512 long bseek(file, offset, ptrname) long offset; { int blkno, bytno; blkno = offset / BLKSIZ; bytno = offset % BLKSIZ; seek(file, blkno, (ptrname + 3)); seek(file, bytno, ptrname); return(offset); } long fseek(iop, offset, ptrname) FILE *iop; long offset; { register n, resync; if (iop->_flag&_IOREAD) { resync = 0; if (ptrname==1) { /* relative */ n = iop->_cnt; if (n<0) n = 0; } else { n = offset&01; resync = n; } n = bseek(fileno(iop), offset - n, ptrname); iop->_cnt = 0; if (resync) getc(iop); return(n); } if (iop->_flag&_IOWRT) { fflush(iop); return(bseek(fileno(iop), offset, ptrname)); } _error("fseek\n"); }