s390x: add single-instruction math functions
[musl.git] / src / stdio / ftell.c
blobbb62897a4c7cc710295fd62aae8bb727b116a4d5
1 #include "stdio_impl.h"
2 #include <limits.h>
3 #include <errno.h>
5 off_t __ftello_unlocked(FILE *f)
7 off_t pos = f->seek(f, 0,
8 (f->flags & F_APP) && f->wpos > f->wbase
9 ? SEEK_END : SEEK_CUR);
10 if (pos < 0) return pos;
12 /* Adjust for data in buffer. */
13 return pos - (f->rend - f->rpos) + (f->wpos - f->wbase);
16 off_t __ftello(FILE *f)
18 off_t pos;
19 FLOCK(f);
20 pos = __ftello_unlocked(f);
21 FUNLOCK(f);
22 return pos;
25 long ftell(FILE *f)
27 off_t pos = __ftello(f);
28 if (pos > LONG_MAX) {
29 errno = EOVERFLOW;
30 return -1;
32 return pos;
35 weak_alias(__ftello, ftello);
37 LFS64(ftello);