readdir64.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <errno.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <unistd.h>
  11. #include <dirent.h>
  12. #include "dirstream.h"
  13. struct dirent64 *readdir64(DIR * dir)
  14. {
  15. ssize_t bytes;
  16. struct dirent64 *de;
  17. if (!dir) {
  18. __set_errno(EBADF);
  19. return NULL;
  20. }
  21. __UCLIBC_MUTEX_LOCK(dir->dd_lock);
  22. do {
  23. if (dir->dd_size <= dir->dd_nextloc) {
  24. /* read dir->dd_max bytes of directory entries. */
  25. bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
  26. if (bytes <= 0) {
  27. de = NULL;
  28. goto all_done;
  29. }
  30. dir->dd_size = bytes;
  31. dir->dd_nextloc = 0;
  32. }
  33. de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
  34. /* Am I right? H.J. */
  35. dir->dd_nextloc += de->d_reclen;
  36. /* We have to save the next offset here. */
  37. dir->dd_nextoff = de->d_off;
  38. /* Skip deleted files. */
  39. } while (de->d_ino == 0);
  40. all_done:
  41. __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
  42. return de;
  43. }
  44. libc_hidden_def(readdir64)