readdir64.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <features.h>
  2. #ifdef __UCLIBC_HAS_LFS__
  3. #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
  4. #undef _FILE_OFFSET_BITS
  5. #define _FILE_OFFSET_BITS 64
  6. #endif
  7. #ifndef __USE_LARGEFILE64
  8. # define __USE_LARGEFILE64 1
  9. #endif
  10. /* We absolutely do _NOT_ want interfaces silently
  11. * renamed under us or very bad things will happen... */
  12. #ifdef __USE_FILE_OFFSET64
  13. # undef __USE_FILE_OFFSET64
  14. #endif
  15. #include <dirent.h>
  16. #include <errno.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include <dirent.h>
  21. #include "dirstream.h"
  22. #undef readdir64
  23. struct dirent64 attribute_hidden *__readdir64(DIR * dir)
  24. {
  25. ssize_t bytes;
  26. struct dirent64 *de;
  27. if (!dir) {
  28. __set_errno(EBADF);
  29. return NULL;
  30. }
  31. __pthread_mutex_lock(&(dir->dd_lock));
  32. do {
  33. if (dir->dd_size <= dir->dd_nextloc) {
  34. /* read dir->dd_max bytes of directory entries. */
  35. bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
  36. if (bytes <= 0) {
  37. de = NULL;
  38. goto all_done;
  39. }
  40. dir->dd_size = bytes;
  41. dir->dd_nextloc = 0;
  42. }
  43. de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
  44. /* Am I right? H.J. */
  45. dir->dd_nextloc += de->d_reclen;
  46. /* We have to save the next offset here. */
  47. dir->dd_nextoff = de->d_off;
  48. /* Skip deleted files. */
  49. } while (de->d_ino == 0);
  50. all_done:
  51. __pthread_mutex_unlock(&(dir->dd_lock));
  52. return de;
  53. }
  54. strong_alias(__readdir64,readdir64)
  55. #endif /* __UCLIBC_HAS_LFS__ */