Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #include "stdio_impl.h" |
| 2 | |
| 3 | off_t __ftello_unlocked(FILE *f) |
| 4 | { |
| 5 | off_t pos = f->seek(f, 0, SEEK_CUR); |
Rich Felker | dba68bf | 2011-07-30 08:02:14 -0400 | [diff] [blame^] | 6 | if (pos < 0) return pos; |
| 7 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 8 | /* Adjust for data in buffer. */ |
| 9 | return pos - (f->rend - f->rpos) + (f->wpos - f->wbase); |
| 10 | } |
| 11 | |
| 12 | off_t __ftello(FILE *f) |
| 13 | { |
| 14 | off_t pos; |
| 15 | FLOCK(f); |
| 16 | pos = __ftello_unlocked(f); |
| 17 | FUNLOCK(f); |
| 18 | return pos; |
| 19 | } |
| 20 | |
| 21 | long ftell(FILE *f) |
| 22 | { |
| 23 | off_t pos = __ftello(f); |
| 24 | if (pos > LONG_MAX) { |
| 25 | errno = EOVERFLOW; |
| 26 | return -1; |
| 27 | } |
| 28 | return pos; |
| 29 | } |
| 30 | |
| 31 | weak_alias(__ftello, ftello); |
| 32 | |
| 33 | LFS64(ftello); |