readdir64.c 1.5 KB

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