Commit | Line | Data |
---|---|---|
0ad97561 BJ |
1 | /* @(#)ftell.c 4.1 (Berkeley) %G% */ |
2 | /* | |
3 | * Return file offset. | |
4 | * Coordinates with buffering. | |
5 | */ | |
6 | ||
7 | #include <stdio.h> | |
8 | long lseek(); | |
9 | ||
10 | ||
11 | long ftell(iop) | |
12 | FILE *iop; | |
13 | { | |
14 | long tres; | |
15 | register adjust; | |
16 | ||
17 | if (iop->_cnt < 0) | |
18 | iop->_cnt = 0; | |
19 | if (iop->_flag&_IOREAD) | |
20 | adjust = - iop->_cnt; | |
21 | else if (iop->_flag&_IOWRT) { | |
22 | adjust = 0; | |
23 | if (iop->_base && (iop->_flag&_IONBF)==0) | |
24 | adjust = iop->_ptr - iop->_base; | |
25 | } else | |
26 | return(-1); | |
27 | tres = lseek(fileno(iop), 0L, 1); | |
28 | if (tres<0) | |
29 | return(tres); | |
30 | tres += adjust; | |
31 | return(tres); | |
32 | } |