Back to index

cell-binutils  2.17cvs20070401
Functions | Variables
pexecute.c File Reference
#include "config.h"
#include "libiberty.h"

Go to the source code of this file.

Functions

int pexecute (const char *program, char *const *argv, const char *pname, const char *temp_base, char **errmsg_fmt, char **errmsg_arg, int flags)
int pwait (int pid, int *status, int flags ATTRIBUTE_UNUSED)

Variables

static struct pex_objpex
static int idx

Function Documentation

int pexecute ( const char *  program,
char *const argv,
const char *  pname,
const char *  temp_base,
char **  errmsg_fmt,
char **  errmsg_arg,
int  flags 
)

Definition at line 39 of file pexecute.c.

{
  const char *errmsg;
  int err;

  if ((flags & PEXECUTE_FIRST) != 0)
    {
      if (pex != NULL)
       {
         *errmsg_fmt = (char *) "pexecute already in progress";
         *errmsg_arg = NULL;
         return -1;
       }
      pex = pex_init (PEX_USE_PIPES, pname, temp_base);
      idx = 0;
    }
  else
    {
      if (pex == NULL)
       {
         *errmsg_fmt = (char *) "pexecute not in progress";
         *errmsg_arg = NULL;
         return -1;
       }
    }

  errmsg = pex_run (pex,
                  (((flags & PEXECUTE_LAST) != 0 ? PEX_LAST : 0)
                   | ((flags & PEXECUTE_SEARCH) != 0 ? PEX_SEARCH : 0)),
                  program, argv, NULL, NULL, &err);
  if (errmsg != NULL)
    {
      *errmsg_fmt = (char *) errmsg;
      *errmsg_arg = NULL;
      return -1;
    }

  /* Instead of a PID, we just return a one-based index into the
     status values.  We avoid zero just because the old pexecute would
     never return it.  */
  return ++idx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pwait ( int  pid,
int status,
int flags  ATTRIBUTE_UNUSED 
)

Definition at line 85 of file pexecute.c.

{
  /* The PID returned by pexecute is one-based.  */
  --pid;

  if (pex == NULL || pid < 0 || pid >= idx)
    return -1;

  if (pid == 0 && idx == 1)
    {
      if (!pex_get_status (pex, 1, status))
       return -1;
    }
  else
    {
      int *vector;

      vector = XNEWVEC (int, idx);
      if (!pex_get_status (pex, idx, vector))
       {
         free (vector);
         return -1;
       }
      *status = vector[pid];
      free (vector);
    }

  /* Assume that we are done after the caller has retrieved the last
     exit status.  The original implementation did not require that
     the exit statuses be retrieved in order, but this implementation
     does.  */
  if (pid + 1 == idx)
    {
      pex_free (pex);
      pex = NULL;
      idx = 0;
    }

  return pid + 1;
}

Here is the call graph for this function:


Variable Documentation

int idx [static]

Definition at line 36 of file pexecute.c.

struct pex_obj* pex [static]

Definition at line 35 of file pexecute.c.