diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:39:52 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:39:52 +0000 |
commit | 8a0efa53e44919bcf5ccb1d3353618a82afdf8bc (patch) | |
tree | 68c3dbf3f2c6fd5d49777def9914d77b5cd4589d /newlib/libc/sys/sysvi386/exec.c | |
parent | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (diff) | |
download | cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.tar.gz cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.tar.bz2 cygnal-8a0efa53e44919bcf5ccb1d3353618a82afdf8bc.zip |
import newlib-2000-02-17 snapshot
Diffstat (limited to 'newlib/libc/sys/sysvi386/exec.c')
-rw-r--r-- | newlib/libc/sys/sysvi386/exec.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/newlib/libc/sys/sysvi386/exec.c b/newlib/libc/sys/sysvi386/exec.c new file mode 100644 index 000000000..6587d50a7 --- /dev/null +++ b/newlib/libc/sys/sysvi386/exec.c @@ -0,0 +1,54 @@ +#include <sys/unistd.h> +#include <errno.h> + +extern char **environ; + +int +execv (const char *path, char * const *args) { + extern int execve (const char *, char * const *, char * const*); + return execve (path, args, environ); +} + +int +execl(const char *path, const char *arg1, ...) { + return execv (path, &arg1); +} + +/* + * Copy string, until c or <nul> is encountered. + * NUL-terminate the destination string (s1). + */ + +static char * +strccpy (char *s1, char *s2, char c) { + char *dest = s1; + while (*s2 && *s2 != c) { + *s1++ = *s2++; + } + *s1 = 0; + return dest; +} + +int +execvp(const char *file, char * const *args) { + extern char *getenv (const char *); + char *path = getenv ("PATH"); + char buf[MAXNAMLEN]; + + if (file[0] == '/') { /* absolute pathname -- easy out */ + return execv (file, args); + } + + buf[0] = 0; /* lots of initialization here 8-) */ + while (*path) { + strccpy (buf, path, ':'); + strcat (buf, "/"); + strcat (buf, file); + execv (buf, args); + if (errno != ENOENT) + return -1; + while (*path && *path != ':') + path++; + } + return -1; +} |