readdir64.c 1.3 KB

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