예제 #1
0
파일: execlp.c 프로젝트: Kampi/Zybo-Linux
/* Execute FILE, searching in the `PATH' environment variable if
   it contains no slashes, with all arguments after FILE until a
   NULL pointer and environment from `environ'.  */
int
execlp (const char *file, const char *arg, ...)
{
  ptrdiff_t argc;
  va_list ap;
  va_start (ap, arg);
  for (argc = 1; va_arg (ap, const char *); argc++)
    {
      if (argc == INT_MAX)
	{
	  va_end (ap);
	  errno = E2BIG;
	  return -1;
	}
    }
  va_end (ap);

  /* Although posix does not state execlp as an async-safe function
     it can not use malloc to allocate the arguments since it might
     be used in a vfork scenario and it may lead to malloc internal
     bad state.  */
  ptrdiff_t i;
  char *argv[argc + 1];
  va_start (ap, arg);
  argv[0] = (char *) arg;
  for (i = 1; i <= argc; i++)
    argv[i] = va_arg (ap, char *);
  va_end (ap);

  return __execvpe (file, argv, __environ);
}
예제 #2
0
파일: execvp.c 프로젝트: riscv/riscv-glibc
/* Execute FILE, searching in the `PATH' environment variable if it contains
   no slashes, with arguments ARGV and environment from `environ'.  */
int
execvp (const char *file, char *const argv[])
{
  return __execvpe (file, argv, __environ);
}