ftello.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* 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. #include "_stdio.h"
  8. #ifdef __DO_LARGEFILE
  9. # ifndef __UCLIBC_HAS_LFS__
  10. # error large file support is not enabled!
  11. # endif
  12. # define FTELL __ftello64
  13. # define OFFSET_TYPE __off64_t
  14. #else
  15. # define FTELL ftell
  16. # define OFFSET_TYPE long int
  17. #endif
  18. OFFSET_TYPE FTELL(register FILE *stream)
  19. {
  20. #if defined(__UCLIBC_HAS_LFS__) && !defined(__DO_LARGEFILE)
  21. __offmax_t pos = __ftello64(stream);
  22. if ((sizeof(long) >= sizeof(__offmax_t)) || (((long) pos) == pos)) {
  23. return ((long) pos);
  24. } else {
  25. __set_errno(EOVERFLOW);
  26. return -1;
  27. }
  28. #else
  29. __offmax_t pos = 0;
  30. __STDIO_AUTO_THREADLOCK_VAR;
  31. __STDIO_AUTO_THREADLOCK(stream);
  32. __STDIO_STREAM_VALIDATE(stream);
  33. if ((__SEEK(stream, &pos, SEEK_CUR) < 0)
  34. || (__stdio_adjust_position(stream, &pos) < 0)) {
  35. pos = -1;
  36. }
  37. __STDIO_AUTO_THREADUNLOCK(stream);
  38. return pos;
  39. #endif
  40. }
  41. #ifdef __DO_LARGEFILE
  42. weak_alias(__ftello64,ftello64);
  43. #else
  44. weak_alias(ftell,ftello);
  45. #endif