Back to index

glibc  2.9
tst-fdopendir2.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <dirent.h>
00003 #include <stdio.h>
00004 #include <unistd.h>
00005 
00006 
00007 static int
00008 do_test (void)
00009 {
00010   char tmpl[] = "/tmp/tst-fdopendir2-XXXXXX";
00011   int fd = mkstemp (tmpl);
00012   if (fd == -1)
00013     {
00014       puts ("cannot open temp file");
00015       return 1;
00016     }
00017 
00018   errno = 0;
00019   DIR *d = fdopendir (fd);
00020 
00021   int e = errno;
00022 
00023   close (fd);
00024   unlink (tmpl);
00025 
00026   if (d != NULL)
00027     {
00028       puts ("fdopendir with normal file descriptor did not fail");
00029       return 1;
00030     }
00031   if (e != ENOTDIR)
00032     {
00033       printf ("fdopendir set errno to %d, not %d as expected\n", e, ENOTDIR);
00034       return 1;
00035     }
00036 
00037   return 0;
00038 }
00039 
00040 #define TEST_FUNCTION do_test ()
00041 #include "../test-skeleton.c"