8 int fd
= dup (fileno (stdout
));
15 FILE *f1
= fdopen (fd
, "w");
18 printf ("fdopen failed: %m\n");
24 FILE *f2
= popen ("echo test1", "r");
27 fprintf (f1
, "1st popen failed: %m\n");
30 FILE *f3
= popen ("echo test2", "r");
31 if (f2
== NULL
|| f3
== NULL
)
33 fprintf (f1
, "2nd popen failed: %m\n");
40 if (getline (&line
, &len
, f2
) != 6)
42 fputs ("could not read line from 1st popen\n", f1
);
45 else if (strcmp (line
, "test1\n") != 0)
47 fprintf (f1
, "read \"%s\"\n", line
);
51 if (getline (&line
, &len
, f2
) != -1)
53 fputs ("second getline did not return -1\n", f1
);
57 if (getline (&line
, &len
, f3
) != 6)
59 fputs ("could not read line from 2nd popen\n", f1
);
62 else if (strcmp (line
, "test2\n") != 0)
64 fprintf (f1
, "read \"%s\"\n", line
);
68 if (getline (&line
, &len
, f3
) != -1)
70 fputs ("second getline did not return -1\n", f1
);
74 int ret
= pclose (f2
);
77 fprintf (f1
, "1st pclose returned %d\n", ret
);
84 fprintf (f1
, "2nd pclose returned %d\n", ret
);
91 #define TEST_FUNCTION do_test ()
92 #include "../test-skeleton.c"