home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdio / ftell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  698 b   |  35 lines

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  3. #include <libc/stubs.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <libc/file.h>
  7. #include <fcntl.h>
  8. #include <libc/dosio.h>
  9.  
  10. long
  11. ftell(FILE *f)
  12. {
  13.   long tres;
  14.   int adjust=0;
  15.  
  16.   if (f->_cnt < 0)
  17.     f->_cnt = 0;
  18.   if (f->_flag&_IOREAD)
  19.   {
  20.     adjust = - f->_cnt;
  21.   }
  22.   else if (f->_flag&(_IOWRT|_IORW))
  23.   {
  24.     if (f->_flag&_IOWRT && f->_base && (f->_flag&_IONBF)==0)
  25.       adjust = f->_ptr - f->_base;
  26.   }
  27.   else
  28.     return -1;
  29.   tres = lseek(fileno(f), 0L, 1);
  30.   if (tres<0)
  31.     return tres;
  32.   tres += adjust;
  33.   return tres;
  34. }
  35.