execvp.c revision 5d54f3d8999eac1762fe0a8c7177d20f1f201fae
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*LINTLIBRARY*/
/*
* execlp(name, arg,...,0) (like execl, but does path search)
* execvp(name, argv) (like execv, but does path search)
*/
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
static char *execat(char *, char *, char *);
int
{
int r;
return (r);
}
int
{
char *pathstr;
char fname[MAXPATHLEN];
char *newargs[256];
int i;
char *cp;
unsigned etxtbsy = 1;
int eacces = 0;
do {
switch (errno) {
case ENOEXEC:
newargs[0] = "sh";
if (i >= 254) {
return(-1);
}
}
return (-1);
case ETXTBSY:
if (++etxtbsy > 5)
return (-1);
goto retry;
case EACCES:
++eacces;
break;
case ENOMEM:
case E2BIG:
case EFAULT:
return (-1);
}
} while (cp);
if (eacces)
return (-1);
}
static char *
{
char *s;
char *end;
s = si;
end = s + MAXPATHLEN;
*s++ = *s1++;
*s++ = '/';
*s++ = *s2++;
*s = '\0';
}