xref: /onnv-gate/usr/src/lib/libc/port/sys/execl.c (revision 6879:150dcecba680)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56812Sraf  * Common Development and Distribution License (the "License").
66812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216812Sraf 
220Sstevel@tonic-gate /*
236812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
306812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  *	execl(name, arg0, arg1, ..., argn, 0)
340Sstevel@tonic-gate  *	environment automatically passed.
350Sstevel@tonic-gate  */
360Sstevel@tonic-gate 
376812Sraf #pragma weak _execl = execl
380Sstevel@tonic-gate 
396812Sraf #include "lint.h"
400Sstevel@tonic-gate #include <alloca.h>
410Sstevel@tonic-gate #include <malloc.h>
420Sstevel@tonic-gate #include <stdarg.h>
430Sstevel@tonic-gate #include <sys/types.h>
440Sstevel@tonic-gate #include <unistd.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*VARARGS1*/
470Sstevel@tonic-gate int
execl(const char * name,const char * arg0,...)480Sstevel@tonic-gate execl(const char *name, const char *arg0, ...)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 	char **argp;
510Sstevel@tonic-gate 	va_list args;
520Sstevel@tonic-gate 	char **argvec;
53*6879Sraf 	extern char **_environ;
540Sstevel@tonic-gate 	int err;
550Sstevel@tonic-gate 	int nargs = 0;
560Sstevel@tonic-gate 	char *nextarg;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	/*
590Sstevel@tonic-gate 	 * count the number of arguments in the variable argument list
600Sstevel@tonic-gate 	 * and allocate an argument vector for them on the stack,
610Sstevel@tonic-gate 	 * adding an extra element for a terminating null pointer
620Sstevel@tonic-gate 	 */
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	va_start(args, arg0);
650Sstevel@tonic-gate 	while (va_arg(args, char *) != (char *)0) {
660Sstevel@tonic-gate 		nargs++;
670Sstevel@tonic-gate 	}
680Sstevel@tonic-gate 	va_end(args);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/*
710Sstevel@tonic-gate 	 * load the arguments in the variable argument list
720Sstevel@tonic-gate 	 * into the argument vector and add the terminating null pointer
730Sstevel@tonic-gate 	 */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	va_start(args, arg0);
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	/* workaround for bugid 1242839 */
780Sstevel@tonic-gate 	argvec = (char **)alloca((size_t)((nargs + 2) * sizeof (char *)));
790Sstevel@tonic-gate 	argp = argvec;
800Sstevel@tonic-gate 	*argp++ = (char *)arg0;
810Sstevel@tonic-gate 	while ((nextarg = va_arg(args, char *)) != (char *)0) {
820Sstevel@tonic-gate 		*argp++ = nextarg;
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate 	va_end(args);
850Sstevel@tonic-gate 	*argp = (char *)0;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	/*
880Sstevel@tonic-gate 	 * call execve()
890Sstevel@tonic-gate 	 */
900Sstevel@tonic-gate 
91*6879Sraf 	err = execve(name, argvec, _environ);
920Sstevel@tonic-gate 	return (err);
930Sstevel@tonic-gate }
94