Commit | Line | Data |
---|---|---|
2ce81398 DS |
1 | #if defined(LIBC_SCCS) && !defined(lint) |
2 | static char sccsid[] = "@(#)ftell.c 5.2 (Berkeley) %G%"; | |
3 | #endif LIBC_SCCS and not lint | |
b8f253e8 | 4 | |
0ad97561 BJ |
5 | /* |
6 | * Return file offset. | |
7 | * Coordinates with buffering. | |
8 | */ | |
9 | ||
10 | #include <stdio.h> | |
11 | long lseek(); | |
12 | ||
13 | ||
14 | long ftell(iop) | |
41e01b3e | 15 | register FILE *iop; |
0ad97561 | 16 | { |
41e01b3e | 17 | register long tres; |
0ad97561 BJ |
18 | register adjust; |
19 | ||
20 | if (iop->_cnt < 0) | |
21 | iop->_cnt = 0; | |
22 | if (iop->_flag&_IOREAD) | |
23 | adjust = - iop->_cnt; | |
d8af6b8b | 24 | else if (iop->_flag&(_IOWRT|_IORW)) { |
0ad97561 | 25 | adjust = 0; |
d8af6b8b | 26 | if (iop->_flag&_IOWRT && iop->_base && (iop->_flag&_IONBF)==0) |
0ad97561 BJ |
27 | adjust = iop->_ptr - iop->_base; |
28 | } else | |
29 | return(-1); | |
30 | tres = lseek(fileno(iop), 0L, 1); | |
31 | if (tres<0) | |
32 | return(tres); | |
33 | tres += adjust; | |
34 | return(tres); | |
35 | } |