home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / libc / stdio / ftell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-05-05  |  516 b   |  32 lines

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