Back to index

glibc  2.9
tst-popen2.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <error.h>
00003 #include <pthread.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <unistd.h>
00008 
00009 static void *
00010 dummy (void *x)
00011 {
00012   return NULL;
00013 }
00014 
00015 static char buf[sizeof "something\n"];
00016 
00017 static int
00018 do_test (void)
00019 {
00020   FILE *f;
00021   pthread_t p;
00022   int err;
00023 
00024   f = popen ("echo something", "r");
00025   if (f == NULL)
00026     error (EXIT_FAILURE, errno, "popen failed");
00027   if (fgets (buf, sizeof (buf), f) == NULL)
00028     error (EXIT_FAILURE, 0, "fgets failed");
00029   if (strcmp (buf, "something\n"))
00030     error (EXIT_FAILURE, 0, "read wrong data");
00031   if (pclose (f))
00032     error (EXIT_FAILURE, errno, "pclose returned non-zero");
00033   if ((err = pthread_create (&p, NULL, dummy, NULL)))
00034     error (EXIT_FAILURE, err, "pthread_create failed");
00035   if ((err = pthread_join (p, NULL)))
00036     error (EXIT_FAILURE, err, "pthread_join failed");
00037   exit (0);
00038 }
00039 
00040 #define TEST_FUNCTION do_test ()
00041 #include "../test-skeleton.c"