Commit | Line | Data |
---|---|---|
41e01b3e | 1 | /* @(#)ftell.c 4.3 (Berkeley) %G% */ |
0ad97561 BJ |
2 | /* |
3 | * Return file offset. | |
4 | * Coordinates with buffering. | |
5 | */ | |
6 | ||
7 | #include <stdio.h> | |
8 | long lseek(); | |
9 | ||
10 | ||
11 | long ftell(iop) | |
41e01b3e | 12 | register FILE *iop; |
0ad97561 | 13 | { |
41e01b3e | 14 | register long tres; |
0ad97561 BJ |
15 | register adjust; |
16 | ||
17 | if (iop->_cnt < 0) | |
18 | iop->_cnt = 0; | |
19 | if (iop->_flag&_IOREAD) | |
20 | adjust = - iop->_cnt; | |
d8af6b8b | 21 | else if (iop->_flag&(_IOWRT|_IORW)) { |
0ad97561 | 22 | adjust = 0; |
d8af6b8b | 23 | if (iop->_flag&_IOWRT && iop->_base && (iop->_flag&_IONBF)==0) |
0ad97561 BJ |
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 | } |