Subject: Re: CVS commit: basesrc/lib/libc/gen
To: None <simonb@netbsd.org>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: source-changes
Date: 09/18/2001 14:38:48
Simon Burge <simonb@netbsd.org> writes:

> Module Name:	basesrc
> Committed By:	simonb
> Date:		Tue Sep 18 05:09:38 UTC 2001
> 
> Modified Files:
> 	basesrc/lib/libc/gen: execvp.c

I guess the first alloca and strcpy is unnecessary.  Also, it calls
strlen within the loop but it always returns same value.  How about
following?

enami.
Index: execvp.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/gen/execvp.c,v
retrieving revision 1.17
diff -c -r1.17 execvp.c
*** execvp.c	2001/09/18 05:09:37	1.17
--- execvp.c	2001/09/18 05:25:42
***************
*** 70,93 ****
  	const char **memp;
  	int cnt;
  	size_t lp, ln;
- 	char *p;
  	int eacces = 0;
  	unsigned int etxtbsy = 0;
! 	char *cur, *path, buf[PATH_MAX];
! 	const char *bp;
  
  	_DIAGASSERT(name != NULL);
  
  	/* "" is not a valid filename; check this before traversing PATH. */
  	if (name[0] == '\0') {
  		errno = ENOENT;
- 		path = NULL;
  		goto done;
  	}
  	/* If it's an absolute or relative path name, it's easy. */
  	if (strchr(name, '/')) {
  		bp = name;
! 		cur = path = NULL;
  		goto retry;
  	}
  	bp = buf;
--- 70,91 ----
  	const char **memp;
  	int cnt;
  	size_t lp, ln;
  	int eacces = 0;
  	unsigned int etxtbsy = 0;
! 	char buf[PATH_MAX];
! 	const char *bp, *path, *p;
  
  	_DIAGASSERT(name != NULL);
  
  	/* "" is not a valid filename; check this before traversing PATH. */
  	if (name[0] == '\0') {
  		errno = ENOENT;
  		goto done;
  	}
  	/* If it's an absolute or relative path name, it's easy. */
  	if (strchr(name, '/')) {
  		bp = name;
! 		path = "";
  		goto retry;
  	}
  	bp = buf;
***************
*** 95,115 ****
  	/* Get the path we're searching. */
  	if (!(path = getenv("PATH")))
  		path = _PATH_DEFPATH;
- 	cur = alloca(strlen(path) + 1);
- 	strcpy(cur, path);
- 	path = cur;
  
! 	while ((p = strsep(&cur, ":")) != NULL) {
  		/*
  		 * It's a SHELL path -- double, leading and trailing colons
  		 * mean the current directory.
  		 */
! 		if (!*p) {
  			p = ".";
  			lp = 1;
  		} else
! 			lp = strlen(p);
! 		ln = strlen(name);
  
  		/*
  		 * If the path is too long complain.  This is a possible
--- 93,113 ----
  	/* Get the path we're searching. */
  	if (!(path = getenv("PATH")))
  		path = _PATH_DEFPATH;
  
! 	ln = strlen(name);
! 	do {
! 		/* Find this path element. */
! 		for (p = path; *path != 0 && *path != ':'; path++)
! 			continue;
  		/*
  		 * It's a SHELL path -- double, leading and trailing colons
  		 * mean the current directory.
  		 */
! 		if (p == path) {
  			p = ".";
  			lp = 1;
  		} else
! 			lp = path - p;
  
  		/*
  		 * If the path is too long complain.  This is a possible
***************
*** 154,160 ****
  		default:
  			goto done;
  		}
! 	}
  	if (eacces)
  		errno = EACCES;
  	else if (!errno)
--- 152,158 ----
  		default:
  			goto done;
  		}
! 	} while (*path++ == ':');	/* Otherwise, *path is NUL */
  	if (eacces)
  		errno = EACCES;
  	else if (!errno)