readdir64.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <features.h>
  2. #ifdef __UCLIBC_HAVE_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_FILE_OFFSET64
  8. # define __USE_FILE_OFFSET64 1
  9. #endif
  10. #ifndef __USE_LARGEFILE64
  11. # define __USE_LARGEFILE64 1
  12. #endif
  13. #include <dirent.h>
  14. #include <errno.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include <dirent.h>
  19. #include "dirstream.h"
  20. extern int getdents64 __P ((unsigned int fd, struct dirent64 *dirp, unsigned int count));
  21. struct dirent64 *readdir64(DIR * dir)
  22. {
  23. int result;
  24. struct dirent64 *de;
  25. if (!dir) {
  26. __set_errno(EBADF);
  27. return NULL;
  28. }
  29. /* Are we running an old kernel? */
  30. if (dir->dd_getdents == no_getdents) {
  31. abort();
  32. }
  33. if (dir->dd_size <= dir->dd_nextloc) {
  34. /* read dir->dd_max bytes of directory entries. */
  35. result = getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
  36. /* We assume we have getdents64 (). */
  37. dir->dd_getdents = have_getdents;
  38. if (result <= 0) {
  39. result = -result;
  40. if (result > 0) {
  41. /* Are we right? */
  42. if (result == ENOSYS) {
  43. dir->dd_getdents = no_getdents;
  44. abort();
  45. }
  46. __set_errno(result);
  47. }
  48. return NULL;
  49. }
  50. dir->dd_size = result;
  51. dir->dd_nextloc = 0;
  52. }
  53. de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
  54. /* Am I right? H.J. */
  55. dir->dd_nextloc += de->d_reclen;
  56. /* We have to save the next offset here. */
  57. dir->dd_nextoff = de->d_off;
  58. return de;
  59. }
  60. #endif /* __UCLIBC_HAVE_LFS__ */