blob: 3720809dc2673f2b0ab762df47ca94df882c6e6b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <errno.h>
2#include <dirent.h>
3#include <stdio.h>
4#include <unistd.h>
5
6
7static int
8do_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"