]> sourceware.org Git - glibc.git/blame - posix/execle.c
Update.
[glibc.git] / posix / execle.c
CommitLineData
b0df72f4 1/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc.
c84142e8 2 This file is part of the GNU C Library.
28f540f4 3
c84142e8
UD
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
28f540f4 8
c84142e8
UD
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
28f540f4 13
c84142e8
UD
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4 18
f671aeab 19#include <alloca.h>
28f540f4
RM
20#include <unistd.h>
21#include <stdarg.h>
22#include <stddef.h>
c84142e8 23#include <string.h>
28f540f4
RM
24
25/* Execute PATH with all arguments after PATH until a NULL pointer,
26 and the argument after that for environment. */
27int
c84142e8 28execle (const char *path, const char *arg, ...)
28f540f4 29{
c84142e8
UD
30 size_t argv_max = 1024;
31 const char **argv = alloca (argv_max * sizeof (const char *));
32 const char *const *envp;
33 unsigned int i;
28f540f4 34 va_list args;
c84142e8 35 argv[0] = arg;
28f540f4
RM
36
37 va_start(args, arg);
b0df72f4
UD
38 i = 0;
39 while (argv[i++] != NULL)
28f540f4 40 {
c84142e8
UD
41 if (i == argv_max)
42 {
43 const char **nptr = alloca ((argv_max *= 2) * sizeof (const char *));
44
45 if ((char *) nptr + argv_max == (char *) argv)
46 {
47 /* Stack grows down. */
48 argv = (const char **) memcpy (nptr, argv, i);
49 argv_max += i;
50 }
51 else if ((char *) argv + i == (char *) nptr)
52 /* Stack grows up. */
53 argv_max += i;
54 else
55 /* We have a hole in the stack. */
56 argv = (const char **) memcpy (nptr, argv, i);
57 }
58
59 argv[i] = va_arg (args, const char *);
60 }
28f540f4 61
c84142e8 62 envp = va_arg(args, const char *const *);
28f540f4
RM
63 va_end(args);
64
c84142e8 65 return __execve(path, (char *const *) argv, (char *const *) envp);
28f540f4 66}
This page took 0.08182 seconds and 5 git commands to generate.