telldir.c 590 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <errno.h>
  2. #include <unistd.h>
  3. #include "dirstream.h"
  4. off_t telldir(DIR * dir)
  5. {
  6. off_t offset;
  7. if (!dir) {
  8. __set_errno(EBADF);
  9. return -1;
  10. }
  11. switch (dir->dd_getdents) {
  12. case no_getdents:
  13. /* We are running the old kernel. This is the starting offset
  14. of the next readdir(). */
  15. offset = lseek(dir->dd_fd, 0, SEEK_CUR);
  16. break;
  17. case unknown:
  18. /* readdir () is not called yet. but seekdir () may be called. */
  19. case have_getdents:
  20. /* The next entry. */
  21. offset = dir->dd_nextoff;
  22. break;
  23. default:
  24. __set_errno(EBADF);
  25. offset = -1;
  26. }
  27. return offset;
  28. }