12a6b7db3Sskrll /* Execute a program and wait for a result.
2*f22f0ef4Schristos    Copyright (C) 2005-2022 Free Software Foundation, Inc.
32a6b7db3Sskrll 
42a6b7db3Sskrll This file is part of the libiberty library.
52a6b7db3Sskrll Libiberty is free software; you can redistribute it and/or
62a6b7db3Sskrll modify it under the terms of the GNU Library General Public
72a6b7db3Sskrll License as published by the Free Software Foundation; either
82a6b7db3Sskrll version 2 of the License, or (at your option) any later version.
92a6b7db3Sskrll 
102a6b7db3Sskrll Libiberty is distributed in the hope that it will be useful,
112a6b7db3Sskrll but WITHOUT ANY WARRANTY; without even the implied warranty of
122a6b7db3Sskrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
132a6b7db3Sskrll Library General Public License for more details.
142a6b7db3Sskrll 
152a6b7db3Sskrll You should have received a copy of the GNU Library General Public
162a6b7db3Sskrll License along with libiberty; see the file COPYING.LIB.  If not,
172a6b7db3Sskrll write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
182a6b7db3Sskrll Boston, MA 02110-1301, USA.  */
192a6b7db3Sskrll 
202a6b7db3Sskrll #include "config.h"
212a6b7db3Sskrll #include "libiberty.h"
222a6b7db3Sskrll 
232a6b7db3Sskrll const char *
pex_one(int flags,const char * executable,char * const * argv,const char * pname,const char * outname,const char * errname,int * status,int * err)242a6b7db3Sskrll pex_one (int flags, const char *executable, char * const *argv,
252a6b7db3Sskrll 	 const char *pname, const char *outname, const char *errname,
262a6b7db3Sskrll 	 int *status, int *err)
272a6b7db3Sskrll {
282a6b7db3Sskrll   struct pex_obj *obj;
292a6b7db3Sskrll   const char *errmsg;
302a6b7db3Sskrll 
312a6b7db3Sskrll   obj = pex_init (0, pname, NULL);
322a6b7db3Sskrll   errmsg = pex_run (obj, flags, executable, argv, outname, errname, err);
332a6b7db3Sskrll   if (errmsg == NULL)
342a6b7db3Sskrll     {
352a6b7db3Sskrll       if (!pex_get_status (obj, 1, status))
362a6b7db3Sskrll 	{
372a6b7db3Sskrll 	  *err = 0;
382a6b7db3Sskrll 	  errmsg = "pex_get_status failed";
392a6b7db3Sskrll 	}
402a6b7db3Sskrll     }
412a6b7db3Sskrll   pex_free (obj);
422a6b7db3Sskrll   return errmsg;
432a6b7db3Sskrll }
44