]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/libh/execsh.c
Updated documentation and comments about sendmail/pipe.
[nmh] / docs / historical / mh-jun-1982 / Extras / libh / execsh.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #
9 #include "../h/errors.h"
10 #define NSHARGS 25 /* limit on number of args to shell command file */
11 execvsh(name,args)
12 char *name, **args;
13 {
14 extern errno;
15 register char **v1, **v2;
16 char *shvec[NSHARGS];
17
18 v2 = args;
19 for (v1 = v2; *v1; )
20 if (*v1++ == -1) *--v1 = 0;
21 execv(name, v2);
22 /* return 0 if not found, -1 if not executable */
23 if (errno == ENOENT || errno == EACCES)
24 return (0);
25 else if (errno != ENOEXEC)
26 return(-1);
27 v1 = shvec;
28 *v1++ = "sh";
29 *v1++ = name;
30 *v2++ = "/bin/sh";
31 while (*v1++ = *v2++) {
32 if (v1 >= &shvec[NSHARGS]) {
33 errno = E2BIG;
34 return(-1);
35 }
36 }
37 execv(args[0], shvec);
38 return(-1);
39 }
40
41 execlsh(name,arg0,arg1,arg2)
42 char *name, *arg0, *arg1, *arg2;
43 {
44 return(execvsh(name,&arg0));
45 }