readdir64.c 1.4 KB

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