1*2011Swnj /* @(#)ftell.c 4.1 (Berkeley) 12/21/80 */ 2*2011Swnj /* 3*2011Swnj * Return file offset. 4*2011Swnj * Coordinates with buffering. 5*2011Swnj */ 6*2011Swnj 7*2011Swnj #include <stdio.h> 8*2011Swnj long lseek(); 9*2011Swnj 10*2011Swnj 11*2011Swnj long ftell(iop) 12*2011Swnj FILE *iop; 13*2011Swnj { 14*2011Swnj long tres; 15*2011Swnj register adjust; 16*2011Swnj 17*2011Swnj if (iop->_cnt < 0) 18*2011Swnj iop->_cnt = 0; 19*2011Swnj if (iop->_flag&_IOREAD) 20*2011Swnj adjust = - iop->_cnt; 21*2011Swnj else if (iop->_flag&_IOWRT) { 22*2011Swnj adjust = 0; 23*2011Swnj if (iop->_base && (iop->_flag&_IONBF)==0) 24*2011Swnj adjust = iop->_ptr - iop->_base; 25*2011Swnj } else 26*2011Swnj return(-1); 27*2011Swnj tres = lseek(fileno(iop), 0L, 1); 28*2011Swnj if (tres<0) 29*2011Swnj return(tres); 30*2011Swnj tres += adjust; 31*2011Swnj return(tres); 32*2011Swnj } 33