blob: e8ff36533e809a62ba267d00a982ecf210241c96 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
2 *
3 * GNU Library General Public License (LGPL) version 2 or later.
4 *
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
7
8#include "_stdio.h"
9
10#ifndef __DO_LARGEFILE
11# define FTELL ftell
12# define OFFSET_TYPE long int
13#endif
14
15OFFSET_TYPE FTELL(register FILE *stream)
16{
17#if defined(__UCLIBC_HAS_LFS__) && !defined(__DO_LARGEFILE)
18
19 __offmax_t pos = ftello64(stream);
20
21 if ((sizeof(long) >= sizeof(__offmax_t)) || (((long) pos) == pos)) {
22 return ((long) pos);
23 } else {
24 __set_errno(EOVERFLOW);
25 return -1;
26 }
27
28#else
29
30 __offmax_t pos = 0;
31 __STDIO_AUTO_THREADLOCK_VAR;
32
33 __STDIO_AUTO_THREADLOCK(stream);
34
35 __STDIO_STREAM_VALIDATE(stream);
36
37 if ((__SEEK(stream, &pos,
38 ((__STDIO_STREAM_IS_WRITING(stream)
39 && (stream->__modeflags & __FLAG_APPEND))
40 ? SEEK_END : SEEK_CUR)) < 0)
41 || (__stdio_adjust_position(stream, &pos) < 0)) {
42 pos = -1;
43 }
44
45 __STDIO_AUTO_THREADUNLOCK(stream);
46
47 return pos;
48
49#endif
50}
51
52#ifdef __DO_LARGEFILE
53libc_hidden_def(ftello64)
54#else
55libc_hidden_def(ftell)
56strong_alias(ftell,ftello)
57#endif