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