Back to index

glibc  2.9
tst-popen.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 
00023   pthread_create (&p, NULL, dummy, NULL);
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   exit (0);
00034 }
00035 
00036 #define TEST_FUNCTION do_test ()
00037 #include "../test-skeleton.c"