readdir64.c 1.3 KB

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