malloc: add glibc compat symbols
[uclibc-ng.git] / libc / stdio / ftello.c
blobf19735cb76bd68112c511dbbb5d7a10fc39d7964
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include "_stdio.h"
10 #ifndef __DO_LARGEFILE
11 # define FTELL ftell
12 # define OFFSET_TYPE long int
13 #endif
15 OFFSET_TYPE FTELL(register FILE *stream)
17 #if !defined(__DO_LARGEFILE)
19 __offmax_t pos = ftello64(stream);
21 if ((sizeof(long) >= sizeof(__offmax_t)) || (((long) pos) == pos)) {
22 return ((long) pos);
23 } else {
24 __set_errno(EOVERFLOW);
25 return -1;
28 #else
30 __offmax_t pos = 0;
31 __STDIO_AUTO_THREADLOCK_VAR;
33 __STDIO_AUTO_THREADLOCK(stream);
35 __STDIO_STREAM_VALIDATE(stream);
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;
45 __STDIO_AUTO_THREADUNLOCK(stream);
47 return pos;
49 #endif
52 #ifdef __DO_LARGEFILE
53 libc_hidden_def(ftello64)
54 #else
55 libc_hidden_def(ftell)
56 strong_alias_untyped(ftell,ftello)
57 #endif