Welcome to mirror list, hosted at ThFree Co, Russian Federation.

exec.c « sysvi386 « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6587d50a7cc8786699e6da7a464fa6b2a8449774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}