ftello.c 1.1 KB

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