telldir.c 613 B

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