2 * ftell.c - obtain the value of the file-position indicator of a stream
4 /* $Id: ftell.c,v 1.5 1994/06/24 11:50:10 ceriel Exp $ */
8 #if (SEEK_CUR != 1) || (SEEK_SET != 0) || (SEEK_END != 2)
9 #error SEEK_* values are wrong
14 #include <sys/types.h>
16 off_t _lseek(int fildes, off_t offset, int whence);
18 long ftell(FILE *stream)
23 if (io_testflag(stream,_IOREADING))
24 adjust = -stream->_count;
25 else if (io_testflag(stream,_IOWRITING)
27 && !io_testflag(stream,_IONBF))
28 adjust = stream->_ptr - stream->_buf;
31 result = _lseek(fileno(stream), 0, SEEK_CUR);
36 result += (long) adjust;