pex-one.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Execute a program and wait for a result.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of the libiberty library.
  4. Libiberty is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. Libiberty 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. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with libiberty; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. #include "config.h"
  17. #include "libiberty.h"
  18. const char *
  19. pex_one (int flags, const char *executable, char * const *argv,
  20. const char *pname, const char *outname, const char *errname,
  21. int *status, int *err)
  22. {
  23. struct pex_obj *obj;
  24. const char *errmsg;
  25. obj = pex_init (0, pname, NULL);
  26. errmsg = pex_run (obj, flags, executable, argv, outname, errname, err);
  27. if (errmsg == NULL)
  28. {
  29. if (!pex_get_status (obj, 1, status))
  30. {
  31. *err = 0;
  32. errmsg = "pex_get_status failed";
  33. }
  34. }
  35. pex_free (obj);
  36. return errmsg;
  37. }