ftello.c 1003 B

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