DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦5e2e8dc3e⟧ TextFile

    Length: 1040 (0x410)
    Types: TextFile
    Notes: UNIX file
    Names: »execvp.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »libc/sys/execvp.c« 

TextFile

/*
 * Version of execv that mimics the
 * actions of the shell in using search
 * rules and running a shell file.
 */

#include <stdio.h>
#include <errno.h>

#define	NFNAME	100		/* Largest filename */

static	char	srch[] = ":/bin";
static	char	shell[] = "/bin/sh";

extern	int	errno;

execvp(name, argp)
char *name;
char *argp[];
{
	char *getenv();
	register char *p1, *p2;
	register char *sp;
	char fname[NFNAME];

	if ((sp = getenv("PATH")) == NULL)
		sp = srch;
	for (;;) {
		p2 = fname;
		while (*sp!='\0' && *sp!=':')
			*p2++ = *sp++;
		p1 = name;
		if (p2 != fname)
			*p2++ = '/';
		while (*p1 != '\0')
			*p2++ = *p1++;
		*p2 = '\0';
		if (*name == '/') {
			execv(name, argp);
			if (errno != ENOEXEC)
				break;
		} else
			execv(fname, argp);
		if (errno == ENOEXEC) {
			register char *sv1, *sv2;

			sv1 = argp[-1];
			sv2 = argp[0];
			argp[-1] = shell;
			argp[0] = fname;
			execv(shell, argp-1);
			argp[-1] = sv1;
			argp[0] = sv2;
			break;
		}
		if (*sp == '\0')
			break;
		if (*sp == ':')
			sp++;
	}
	return (-1);
}