Last change
on this file since 577 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.0 KB
|
Line | |
---|
1 | #include <sys/unistd.h> |
---|
2 | #include <errno.h> |
---|
3 | |
---|
4 | extern char **environ; |
---|
5 | |
---|
6 | int |
---|
7 | execv (const char *path, char * const *args) { |
---|
8 | extern int execve (const char *, char * const *, char * const*); |
---|
9 | return execve (path, args, environ); |
---|
10 | } |
---|
11 | |
---|
12 | int |
---|
13 | execl(const char *path, const char *arg1, ...) { |
---|
14 | return execv (path, &arg1); |
---|
15 | } |
---|
16 | |
---|
17 | /* |
---|
18 | * Copy string, until c or <nul> is encountered. |
---|
19 | * NUL-terminate the destination string (s1). |
---|
20 | */ |
---|
21 | |
---|
22 | static char * |
---|
23 | strccpy (char *s1, char *s2, char c) { |
---|
24 | char *dest = s1; |
---|
25 | while (*s2 && *s2 != c) { |
---|
26 | *s1++ = *s2++; |
---|
27 | } |
---|
28 | *s1 = 0; |
---|
29 | return dest; |
---|
30 | } |
---|
31 | |
---|
32 | int |
---|
33 | execvp(const char *file, char * const *args) { |
---|
34 | extern char *getenv (const char *); |
---|
35 | char *path = getenv ("PATH"); |
---|
36 | char buf[MAXNAMLEN]; |
---|
37 | |
---|
38 | if (file[0] == '/') { /* absolute pathname -- easy out */ |
---|
39 | return execv (file, args); |
---|
40 | } |
---|
41 | |
---|
42 | buf[0] = 0; /* lots of initialization here 8-) */ |
---|
43 | while (*path) { |
---|
44 | strccpy (buf, path, ':'); |
---|
45 | strcat (buf, "/"); |
---|
46 | strcat (buf, file); |
---|
47 | execv (buf, args); |
---|
48 | if (errno != ENOENT) |
---|
49 | return -1; |
---|
50 | while (*path && *path != ':') |
---|
51 | path++; |
---|
52 | } |
---|
53 | return -1; |
---|
54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.