readdir64.c 1.6 KB

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