tst-fdopendir2.c 692 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <errno.h>
  2. #include <dirent.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. static int
  7. do_test (void)
  8. {
  9. char tmpl[] = "/tmp/tst-fdopendir2-XXXXXX";
  10. int fd = mkstemp (tmpl);
  11. if (fd == -1)
  12. {
  13. puts ("cannot open temp file");
  14. return 1;
  15. }
  16. errno = 0;
  17. DIR *d = fdopendir (fd);
  18. int e = errno;
  19. close (fd);
  20. unlink (tmpl);
  21. if (d != NULL)
  22. {
  23. puts ("fdopendir with normal file descriptor did not fail");
  24. return 1;
  25. }
  26. if (e != ENOTDIR)
  27. {
  28. printf ("fdopendir set errno to %d, not %d as expected\n", e, ENOTDIR);
  29. return 1;
  30. }
  31. return 0;
  32. }
  33. #define TEST_FUNCTION do_test ()
  34. #include "../test-skeleton.c"