ftell.c 416 B

123456789101112131415161718192021222324
  1. /* $Id$ */
  2. #include <stdio.h>
  3. long ftell(iop)
  4. FILE *iop;
  5. {
  6. long result;
  7. long lseek();
  8. int adjust = 0;
  9. if ( io_testflag(iop,IO_READMODE) )
  10. adjust -= iop->_count;
  11. else if ( io_testflag(iop,IO_WRITEMODE) && iop->_buf && !io_testflag(iop,IO_UNBUFF))
  12. adjust = iop->_ptr - iop->_buf;
  13. result = lseek(fileno(iop), 0L, 1);
  14. if ( result < 0 )
  15. return ( result );
  16. result += (long) adjust;
  17. return(result);
  18. }