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