ftello.c 1.1 KB

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