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

source code of glibc/dirent/tst-fdopendir2.c