xref: /netbsd-src/lib/libc/gen/execle.c (revision 93fc0a3ef4c339469dc754494ba9091efd1d4b5c)
1*93fc0a3eSjoerg /*	$NetBSD: execle.c,v 1.12 2011/06/30 19:46:07 joerg Exp $	*/
261442025Sjtc 
361442025Sjtc /*-
461442025Sjtc  * Copyright (c) 1991, 1993
561442025Sjtc  *	The Regents of the University of California.  All rights reserved.
661442025Sjtc  *
761442025Sjtc  * Redistribution and use in source and binary forms, with or without
861442025Sjtc  * modification, are permitted provided that the following conditions
961442025Sjtc  * are met:
1061442025Sjtc  * 1. Redistributions of source code must retain the above copyright
1161442025Sjtc  *    notice, this list of conditions and the following disclaimer.
1261442025Sjtc  * 2. Redistributions in binary form must reproduce the above copyright
1361442025Sjtc  *    notice, this list of conditions and the following disclaimer in the
1461442025Sjtc  *    documentation and/or other materials provided with the distribution.
15eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
1661442025Sjtc  *    may be used to endorse or promote products derived from this software
1761442025Sjtc  *    without specific prior written permission.
1861442025Sjtc  *
1961442025Sjtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061442025Sjtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161442025Sjtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261442025Sjtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361442025Sjtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461442025Sjtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561442025Sjtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661442025Sjtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761442025Sjtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861442025Sjtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961442025Sjtc  * SUCH DAMAGE.
3061442025Sjtc  */
3161442025Sjtc 
3226cc2d4fSchristos #include <sys/cdefs.h>
3361442025Sjtc #if defined(LIBC_SCCS) && !defined(lint)
3461442025Sjtc #if 0
3561442025Sjtc static char sccsid[] = "@(#)exec.c	8.1 (Berkeley) 6/4/93";
3661442025Sjtc #else
37*93fc0a3eSjoerg __RCSID("$NetBSD: execle.c,v 1.12 2011/06/30 19:46:07 joerg Exp $");
3861442025Sjtc #endif
3961442025Sjtc #endif /* LIBC_SCCS and not lint */
4061442025Sjtc 
4143fa6fe3Sjtc #include "namespace.h"
42077b67efSwiz #include <stdarg.h>
4361442025Sjtc #include <stdlib.h>
4461442025Sjtc #include <unistd.h>
4561442025Sjtc 
4643fa6fe3Sjtc #ifdef __weak_alias
__weak_alias(execle,_execle)4760549036Smycroft __weak_alias(execle,_execle)
4843fa6fe3Sjtc #endif
4943fa6fe3Sjtc 
5061442025Sjtc int
5161442025Sjtc execle(const char *name, const char *arg, ...)
5261442025Sjtc {
5361442025Sjtc 	va_list ap;
5461442025Sjtc 	char **argv, **envp;
5561442025Sjtc 	int i;
5661442025Sjtc 
57077b67efSwiz 	va_start(ap, arg);
583b0a9ac9Senami 	for (i = 2; va_arg(ap, char *) != NULL; i++)
59c341912eSchristos 		continue;
6061442025Sjtc 	va_end(ap);
6161442025Sjtc 
6261442025Sjtc 	argv = alloca(i * sizeof (char *));
6361442025Sjtc 
64077b67efSwiz 	va_start(ap, arg);
65c341912eSchristos 	argv[0] = __UNCONST(arg);
66c341912eSchristos 	for (i = 1; (argv[i] = va_arg(ap, char *)) != NULL; i++)
67c341912eSchristos 		continue;
68c341912eSchristos 	envp = va_arg(ap, char **);
6961442025Sjtc 	va_end(ap);
7061442025Sjtc 
7161442025Sjtc 	return execve(name, argv, envp);
7261442025Sjtc }
73