1 /* execvp() - execute with PATH search and prepared arguments
10 #define execvp _execvp
19 extern char * const **_penviron
; /* The default environment. */
21 int execvp(const char *file
, char * const *argv
)
22 /* Execute the file with a path search on $PATH, just like the shell. The
23 * search continues on the errors ENOENT (not there), and EACCES (file not
24 * executable or leading directories protected.)
25 * Unlike other execvp implementations there is no default path, and no shell
26 * is started for scripts. One is supposed to define $PATH, and use #!/bin/sh.
30 const char *path
; /* $PATH */
31 char *full
; /* Full name to try. */
34 int err
= ENOENT
; /* Error return on failure. */
36 if (strchr(file
, '/') != nil
|| (path
= getenv("PATH")) == nil
)
39 /* Compute the maximum length the full name may have, and align. */
40 full_size
= strlen(path
) + 1 + strlen(file
) + 1 + sizeof(char *) - 1;
41 full_size
&= ~(sizeof(char *) - 1);
44 if ((full
= (char *) sbrk(full_size
)) == (char *) -1) {
49 /* For each directory in the path... */
52 while (*path
!= 0 && *path
!= ':') *f
++= *path
++;
54 if (f
> full
) *f
++= '/';
58 /* Stat first, small speed-up, better for ptrace. */
59 if (stat(full
, &sb
) == -1) continue;
61 (void) execve(full
, argv
, *_penviron
);
63 /* Prefer more interesting errno values then "not there". */
64 if (errno
!= ENOENT
) err
= errno
;
66 /* Continue only on some errors. */
67 if (err
!= ENOENT
&& err
!= EACCES
) break;
68 } while (*path
++ != 0);
70 (void) sbrk(-full_size
);