readdir64.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <_lfs_64.h>
  7. #include <dirent.h>
  8. #include <errno.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12. #include <dirent.h>
  13. #include "dirstream.h"
  14. libc_hidden_proto(readdir64)
  15. struct dirent64 *readdir64(DIR * dir)
  16. {
  17. ssize_t bytes;
  18. struct dirent64 *de;
  19. if (!dir) {
  20. __set_errno(EBADF);
  21. return NULL;
  22. }
  23. __pthread_mutex_lock(&(dir->dd_lock));
  24. do {
  25. if (dir->dd_size <= dir->dd_nextloc) {
  26. /* read dir->dd_max bytes of directory entries. */
  27. bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
  28. if (bytes <= 0) {
  29. de = NULL;
  30. goto all_done;
  31. }
  32. dir->dd_size = bytes;
  33. dir->dd_nextloc = 0;
  34. }
  35. de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
  36. /* Am I right? H.J. */
  37. dir->dd_nextloc += de->d_reclen;
  38. /* We have to save the next offset here. */
  39. dir->dd_nextoff = de->d_off;
  40. /* Skip deleted files. */
  41. } while (de->d_ino == 0);
  42. all_done:
  43. __pthread_mutex_unlock(&(dir->dd_lock));
  44. return de;
  45. }
  46. libc_hidden_def(readdir64)