while ((p = strsep(&path, ":")) != NULL) {
while ((p = strsep(&pathcpy, ":")) != NULL) {
findprog(char *prog, char *path, int progmode, int allmatches){	char *p, filename[MAXPATHLEN];	int proglen, plen, rval = 0;	struct stat sbuf;	/* Special case if prog contains '/' */	if (strchr(prog, '/')) {		if ((stat(prog, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&		    access(prog, X_OK) == 0) {			(void)puts(prog);			return (1);		} else {			(void)printf("%s: Command not found.\n", prog);			return (0);		}	}	if ((path = strdup(path)) == NULL)		errx(1, "Can't allocate memory.");	proglen = strlen(prog);	while ((p = strsep(&path, ":")) != NULL) {		if (*p == '\0')			p = ".";		plen = strlen(p);		while (p[plen-1] == '/')			p[--plen] = '\0';	/* strip trailing '/' */		if (plen + 1 + proglen >= sizeof(filename)) {			warnx("%s/%s: %s", p, prog, strerror(ENAMETOOLONG));			free(path);			return (0);		}		snprintf(filename, sizeof(filename), "%s/%s", p, prog);		if ((stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&		    access(filename, X_OK) == 0) {			(void)puts(filename);			rval = 1;			if (!allmatches) {				free(path);				return (rval);			}		}	}	(void)free(path);	/* whereis(1) is silent on failure. */	if (!rval && progmode != PROG_WHEREIS)		(void)printf("%s: Command not found.\n", prog);	return (rval);}