readdir.c 589 B

1234567891011121314151617181920212223242526272829
  1. #include <dirent.h>
  2. #include <fcntl.h>
  3. #include <sys/stat.h>
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <limits.h>
  7. #include "__dirent.h"
  8. #include "syscall.h"
  9. #include "libc.h"
  10. int __getdents(int, struct dirent *, size_t);
  11. struct dirent *readdir(DIR *dir)
  12. {
  13. struct dirent *de;
  14. if (dir->buf_pos >= dir->buf_end) {
  15. int len = __getdents(dir->fd, (void *)dir->buf, sizeof dir->buf);
  16. if (len <= 0) return 0;
  17. dir->buf_end = len;
  18. dir->buf_pos = 0;
  19. }
  20. de = (void *)(dir->buf + dir->buf_pos);
  21. dir->buf_pos += de->d_reclen;
  22. dir->tell = de->d_off;
  23. return de;
  24. }
  25. LFS64(readdir);