main.c 816 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <dirent.h>
  2. #include <errno.h>
  3. #include <stdio.h>
  4. int main() {
  5. printf("%lu\n", sizeof(struct dirent));
  6. DIR* dir = opendir("example_dir/");
  7. if (dir == NULL) {
  8. perror("opendir");
  9. return 1;
  10. }
  11. struct dirent* entry;
  12. //int tell = 0;
  13. for (char counter = 0; (entry = readdir(dir)); counter += 1) {
  14. puts(entry->d_name);
  15. //if (counter == 4) {
  16. // tell = telldir(dir);
  17. //}
  18. }
  19. puts("--- Testing rewind ---");
  20. rewinddir(dir);
  21. entry = readdir(dir);
  22. puts(entry->d_name);
  23. // puts("--- Testing seek ---");
  24. // // Why this doesn't cause it to actually go to the 4th element is beyond
  25. // // me, but glibc acts the same way.
  26. // seekdir(dir, tell);
  27. // entry = readdir(dir);
  28. // puts(entry->d_name);
  29. }