main.c 897 B

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