blob: 3904a1d871dd9229b59ba0c97d13923dfc8d5c14 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#include "stdio_impl.h"
2
3off_t __ftello_unlocked(FILE *f)
4{
5 off_t pos = f->seek(f, 0, SEEK_CUR);
Rich Felkerdba68bf2011-07-30 08:02:14 -04006 if (pos < 0) return pos;
7
Rich Felker0b44a032011-02-12 00:22:29 -05008 /* Adjust for data in buffer. */
9 return pos - (f->rend - f->rpos) + (f->wpos - f->wbase);
10}
11
12off_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
21long 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
31weak_alias(__ftello, ftello);
32
33LFS64(ftello);