Back to index

glibc  2.9
Defines | Functions
execlp.c File Reference
#include <unistd.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stackinfo.h>

Go to the source code of this file.

Defines

#define INITIAL_ARGV_MAX   1024

Functions

int execlp (const char *file, const char *arg,...)

Define Documentation

#define INITIAL_ARGV_MAX   1024

Function Documentation

int execlp ( const char *  file,
const char *  arg,
  ... 
)

Definition at line 31 of file execlp.c.

{
#define INITIAL_ARGV_MAX 1024
  size_t argv_max = INITIAL_ARGV_MAX;
  const char *initial_argv[INITIAL_ARGV_MAX];
  const char **argv = initial_argv;
  va_list args;

  argv[0] = arg;

  va_start (args, arg);
  unsigned int i = 0;
  while (argv[i++] != NULL)
    {
      if (i == argv_max)
       {
         argv_max *= 2;
         const char **nptr = realloc (argv == initial_argv ? NULL : argv,
                                   argv_max * sizeof (const char *));
         if (nptr == NULL)
           {
             if (argv != initial_argv)
              free (argv);
             return -1;
           }
         if (argv == initial_argv)
           /* We have to copy the already filled-in data ourselves.  */
           memcpy (nptr, argv, i * sizeof (const char *));

         argv = nptr;
       }

      argv[i] = va_arg (args, const char *);
    }
  va_end (args);

  int ret = execvp (file, (char *const *) argv);
  if (argv != initial_argv)
    free (argv);

  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function: