home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / FTELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  583 b   |  27 lines

  1. /* ftell.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <io.h>
  6.  
  7. /* Bug: incorrect result with text mode */
  8. /* Bug: does not work with rw files(?) */
  9.  
  10. long ftell (FILE *stream)
  11. {
  12.   long pos;
  13.  
  14.   pos = lseek (stream->handle, 0L, SEEK_CUR);
  15.   if (pos < 0)
  16.     return (-1L);
  17.   if (stream->flags & _IOWRT)
  18.     {
  19.       if (bbuf (stream))
  20.         return (pos + (stream->ptr - stream->buffer));
  21.       else
  22.         return (pos);
  23.     }
  24.   else
  25.     return (pos - stream->rcount);           /* ungetc! */
  26. }
  27.