Back to index

glibc  2.9
tst-popen1.c
Go to the documentation of this file.
00001 #include <fcntl.h>
00002 #include <stdio.h>
00003 
00004 static int
00005 do_test (void)
00006 {
00007   int res = 0;
00008 
00009   FILE *fp = popen ("echo hello", "r");
00010   if (fp == NULL)
00011     {
00012       puts ("first popen failed");
00013       res = 1;
00014     }
00015   else
00016     {
00017       int fd = fileno (fp);
00018       if (fcntl (fd, F_GETFD) == FD_CLOEXEC)
00019        {
00020          puts ("first popen(\"r\") set FD_CLOEXEC");
00021          res = 1;
00022        }
00023 
00024       fclose (fp);
00025     }
00026 
00027   fp = popen ("echo hello", "re");
00028   if (fp == NULL)
00029     {
00030       puts ("second popen failed");
00031       res = 1;
00032     }
00033   else
00034     {
00035       int fd = fileno (fp);
00036       if (fcntl (fd, F_GETFD) != FD_CLOEXEC)
00037        {
00038          puts ("second popen(\"r\") did not set FD_CLOEXEC");
00039          res = 1;
00040        }
00041 
00042       fclose (fp);
00043     }
00044 
00045   return res;
00046 }
00047 
00048 #define TEST_FUNCTION do_test ()
00049 #include "../test-skeleton.c"