main.c 924 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. ERROR_IF(opendir, dir, == NULL);
  10. struct dirent* entry;
  11. //int tell = 0;
  12. for (char counter = 0; (entry = readdir(dir)); counter += 1) {
  13. puts(entry->d_name);
  14. //if (counter == 4) {
  15. // tell = telldir(dir);
  16. //}
  17. }
  18. puts("--- Testing rewind ---");
  19. rewinddir(dir);
  20. entry = readdir(dir);
  21. puts(entry->d_name);
  22. // puts("--- Testing seek ---");
  23. // // Why this doesn't cause it to actually go to the 4th element is beyond
  24. // // me, but glibc acts the same way.
  25. // seekdir(dir, tell);
  26. // entry = readdir(dir);
  27. // puts(entry->d_name);
  28. int c = closedir(dir);
  29. ERROR_IF(closedir, c, == -1);
  30. UNEXP_IF(closedir, c, != 0);
  31. }