1 | #include <fcntl.h> |
---|---|
2 | #include <stdio.h> |
3 | |
4 | static int |
5 | do_test (void) |
6 | { |
7 | int res = 0; |
8 | |
9 | FILE *fp = popen (command: "echo hello", modes: "r"); |
10 | if (fp == NULL) |
11 | { |
12 | puts (s: "first popen failed"); |
13 | res = 1; |
14 | } |
15 | else |
16 | { |
17 | int fd = fileno (fp); |
18 | if (fcntl (fd: fd, F_GETFD) == FD_CLOEXEC) |
19 | { |
20 | puts (s: "first popen(\"r\") set FD_CLOEXEC"); |
21 | res = 1; |
22 | } |
23 | |
24 | pclose (stream: fp); |
25 | } |
26 | |
27 | fp = popen (command: "echo hello", modes: "re"); |
28 | if (fp == NULL) |
29 | { |
30 | puts (s: "second popen failed"); |
31 | res = 1; |
32 | } |
33 | else |
34 | { |
35 | int fd = fileno (fp); |
36 | if (fcntl (fd: fd, F_GETFD) != FD_CLOEXEC) |
37 | { |
38 | puts (s: "second popen(\"r\") did not set FD_CLOEXEC"); |
39 | res = 1; |
40 | } |
41 | |
42 | pclose (stream: fp); |
43 | } |
44 | |
45 | return res; |
46 | } |
47 | |
48 | #define TEST_FUNCTION do_test () |
49 | #include "../test-skeleton.c" |
50 |