ftello.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. weak_alias(__ftello64,ftello64);
  15. #else
  16. # define FTELL ftell
  17. # define OFFSET_TYPE long int
  18. weak_alias(ftell,ftello);
  19. #endif
  20. OFFSET_TYPE FTELL(register FILE *stream)
  21. {
  22. #if defined(__UCLIBC_HAS_LFS__) && !defined(__DO_LARGEFILE)
  23. __offmax_t pos = __ftello64(stream);
  24. if ((sizeof(long) >= sizeof(__offmax_t)) || (((long) pos) == pos)) {
  25. return ((long) pos);
  26. } else {
  27. __set_errno(EOVERFLOW);
  28. return -1;
  29. }
  30. #else
  31. __offmax_t pos = 0;
  32. __STDIO_AUTO_THREADLOCK_VAR;
  33. __STDIO_AUTO_THREADLOCK(stream);
  34. __STDIO_STREAM_VALIDATE(stream);
  35. if ((__SEEK(stream, &pos, SEEK_CUR) < 0)
  36. || (__stdio_adjust_position(stream, &pos) < 0)) {
  37. pos = -1;
  38. }
  39. __STDIO_AUTO_THREADUNLOCK(stream);
  40. return pos;
  41. #endif
  42. }