Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / posix / execvp.c
blobbe7e71cea69a85d57252195b7966f800c0191716
1 #ifndef _NO_EXECVE
3 /* execvp.c */
5 /* This and the other exec*.c files in this directory require
6 the target to provide the _execve syscall. */
8 #include <_ansi.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <dirent.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <ctype.h>
16 #define PATH_DELIM ':'
19 * Copy string, until c or <nul> is encountered.
20 * NUL-terminate the destination string (s1).
23 static char *
24 strccpy (char *s1,
25 char *s2,
26 char c)
28 char *dest = s1;
30 while (*s2 && *s2 != c)
31 *s1++ = *s2++;
32 *s1 = 0;
34 return dest;
37 int
38 execvp (const char *file,
39 char * const argv[])
41 char *path = getenv ("PATH");
42 char buf[MAXNAMLEN];
44 /* If $PATH doesn't exist, just pass FILE on unchanged. */
45 if (!path)
46 return execv (file, argv);
48 /* If FILE contains a directory, don't search $PATH. */
49 if (strchr (file, '/')
51 return execv (file, argv);
53 while (*path)
55 strccpy (buf, path, PATH_DELIM);
56 /* An empty entry means the current directory. */
57 if (*buf != 0 && buf[strlen(buf) - 1] != '/')
58 strcat (buf, "/");
59 strcat (buf, file);
60 if (execv (buf, argv) == -1 && errno != ENOENT)
61 return -1;
62 while (*path && *path != PATH_DELIM)
63 path++;
64 if (*path == PATH_DELIM)
65 path++; /* skip over delim */
68 return -1;
71 #endif /* !_NO_EXECVE */