2008-10-31 21:03:42 +00:00
|
|
|
#ifndef _NO_EXECVE
|
|
|
|
|
2000-02-17 19:39:52 +00:00
|
|
|
/* execlp.c */
|
|
|
|
|
|
|
|
/* This and the other exec*.c files in this directory require
|
|
|
|
the target to provide the _execve syscall. */
|
|
|
|
|
|
|
|
#include <_ansi.h>
|
|
|
|
#include <unistd.h>
|
2025-01-28 17:19:18 +01:00
|
|
|
#ifdef _EXECL_USE_MALLOC
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#else
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
2000-02-17 19:39:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
int
|
2017-12-03 21:43:30 -06:00
|
|
|
execlp (const char *path,
|
2017-12-03 20:28:42 -06:00
|
|
|
const char *arg0, ...)
|
2000-02-17 19:39:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
va_list args;
|
2025-01-28 17:19:18 +01:00
|
|
|
const char **argv;
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
va_start (args, arg0);
|
|
|
|
do
|
|
|
|
i++;
|
|
|
|
while (va_arg (args, const char *) != NULL);
|
|
|
|
va_end (args);
|
|
|
|
#ifndef _EXECL_USE_MALLOC
|
|
|
|
argv = alloca (i * sizeof(const char *));
|
|
|
|
#else
|
|
|
|
argv = malloc (i * sizeof(const char *));
|
|
|
|
if (argv == NULL)
|
|
|
|
{
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2000-02-17 19:39:52 +00:00
|
|
|
|
|
|
|
va_start (args, arg0);
|
|
|
|
argv[0] = arg0;
|
|
|
|
i = 1;
|
|
|
|
do
|
2017-12-03 20:25:16 -06:00
|
|
|
argv[i] = va_arg (args, const char *);
|
2000-02-17 19:39:52 +00:00
|
|
|
while (argv[i++] != NULL);
|
|
|
|
va_end (args);
|
|
|
|
|
2025-01-28 17:19:18 +01:00
|
|
|
i = execvp (path, (char * const *) argv);
|
|
|
|
#ifdef _EXECL_USE_MALLOC
|
|
|
|
free (argv);
|
|
|
|
#endif
|
|
|
|
return i;
|
2000-02-17 19:39:52 +00:00
|
|
|
}
|
2008-10-31 21:03:42 +00:00
|
|
|
|
|
|
|
#endif /* !_NO_EXECVE */
|