ftell.c 517 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "stdio_impl.h"
  2. off_t __ftello_unlocked(FILE *f)
  3. {
  4. off_t pos = f->seek(f, 0, SEEK_CUR);
  5. if (pos < 0) {
  6. FUNLOCK(f);
  7. return pos;
  8. }
  9. /* Adjust for data in buffer. */
  10. return pos - (f->rend - f->rpos) + (f->wpos - f->wbase);
  11. }
  12. off_t __ftello(FILE *f)
  13. {
  14. off_t pos;
  15. FLOCK(f);
  16. pos = __ftello_unlocked(f);
  17. FUNLOCK(f);
  18. return pos;
  19. }
  20. long ftell(FILE *f)
  21. {
  22. off_t pos = __ftello(f);
  23. if (pos > LONG_MAX) {
  24. errno = EOVERFLOW;
  25. return -1;
  26. }
  27. return pos;
  28. }
  29. weak_alias(__ftello, ftello);
  30. LFS64(ftello);