tst-popen1.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <error.h>
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <unistd.h>
  22. static void *
  23. dummy (void *x)
  24. {
  25. return NULL;
  26. }
  27. static char buf[sizeof "something\n"];
  28. static int
  29. do_test (void)
  30. {
  31. FILE *f;
  32. pthread_t p;
  33. int err;
  34. f = popen ("echo something", "r");
  35. if (f == NULL)
  36. error (EXIT_FAILURE, errno, "popen failed");
  37. if (fgets (buf, sizeof (buf), f) == NULL)
  38. error (EXIT_FAILURE, 0, "fgets failed");
  39. if (strcmp (buf, "something\n"))
  40. error (EXIT_FAILURE, 0, "read wrong data");
  41. if (pclose (f))
  42. error (EXIT_FAILURE, errno, "pclose returned non-zero");
  43. if ((err = pthread_create (&p, NULL, dummy, NULL)))
  44. error (EXIT_FAILURE, err, "pthread_create failed");
  45. if ((err = pthread_join (p, NULL)))
  46. error (EXIT_FAILURE, err, "pthread_join failed");
  47. exit (0);
  48. }
  49. #define TEST_FUNCTION do_test ()
  50. #include "../test-skeleton.c"