errno = 0; output = popen ("/bin/cat", "m"); if (output != NULL) { puts ("popen called with illegal mode does not return NULL"); puts ("Test FAILED!"); exit (1); } if (errno != EINVAL) { puts ("popen called with illegal mode does not set errno to EINVAL"); puts ("Test FAILED!"); exit (1); }
main (void){  FILE *output, *input;  int wstatus, rstatus;  /* We must remove this entry to assure the `cat' binary does not use     the perhaps incompatible new shared libraries.  */  unsetenv ("LD_LIBRARY_PATH");  output = popen ("/bin/cat >/tmp/tstpopen.tmp", "w");  if (output == NULL)    {      perror ("popen");      puts ("Test FAILED!");      exit (1);    }  write_data (output);  wstatus = pclose (output);  printf ("writing pclose returned %d\n", wstatus);  input = popen ("/bin/cat /tmp/tstpopen.tmp", "r");  if (input == NULL)    {      perror ("/tmp/tstpopen.tmp");      puts ("Test FAILED!");      exit (1);    }  read_data (input);  rstatus = pclose (input);  printf ("reading pclose returned %d\n", rstatus);  remove ("/tmp/tstpopen.tmp");  puts (wstatus | rstatus  ? "Test FAILED!" : "Test succeeded.");  exit (wstatus | rstatus);}