2
0

main.c 897 B

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