ftello.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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,
  32. ((__STDIO_STREAM_IS_WRITING(stream)
  33. && (stream->__modeflags & __FLAG_APPEND))
  34. ? SEEK_END : SEEK_CUR)) < 0)
  35. || (__stdio_adjust_position(stream, &pos) < 0)) {
  36. pos = -1;
  37. }
  38. __STDIO_AUTO_THREADUNLOCK(stream);
  39. return pos;
  40. #endif
  41. }
  42. #ifdef __DO_LARGEFILE
  43. libc_hidden_def(ftello64)
  44. #else
  45. libc_hidden_def(ftell)
  46. strong_alias(ftell,ftello)
  47. #endif