isblank() implementation.
[minix.git] / lib / libc / stdio / ftell.c
blobd0c147174ea545557aa587f117ffc89c2c051bc7
1 /*
2 * ftell.c - obtain the value of the file-position indicator of a stream
3 */
4 /* $Header$ */
6 #include <stdio.h>
8 #if (SEEK_CUR != 1) || (SEEK_SET != 0) || (SEEK_END != 2)
9 #error SEEK_* values are wrong
10 #endif
12 #include "loc_incl.h"
14 #include <sys/types.h>
16 off_t _lseek(int fildes, off_t offset, int whence);
18 long ftell(FILE *stream)
20 long result;
21 int adjust = 0;
23 if (io_testflag(stream,_IOREADING))
24 adjust = -stream->_count;
25 else if (io_testflag(stream,_IOWRITING)
26 && stream->_buf
27 && !io_testflag(stream,_IONBF))
28 adjust = stream->_ptr - stream->_buf;
29 else adjust = 0;
31 result = _lseek(fileno(stream), (off_t)0, SEEK_CUR);
33 if ( result == -1 )
34 return result;
36 result += (long) adjust;
37 return result;