ftello.c 1.1 KB

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