about summary refs log tree commit diff
path: root/posix/execvp.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-08-20 17:01:09 +0000
committerUlrich Drepper <drepper@redhat.com>1999-08-20 17:01:09 +0000
commitd13ec59a493a36f8bf566dfe414f52a96ab5dc27 (patch)
tree3c5db90684ad6e4d9b64232eba6628a8067806b1 /posix/execvp.c
parentf05ce1953ce9d1c34d0e8ee5657a36726a84dc68 (diff)
downloadglibc-d13ec59a493a36f8bf566dfe414f52a96ab5dc27.tar.gz
glibc-d13ec59a493a36f8bf566dfe414f52a96ab5dc27.tar.xz
glibc-d13ec59a493a36f8bf566dfe414f52a96ab5dc27.zip
Update.
	* posix/execvp.c (execvp): Allocate array name of correct size.
	Optimize inner loop.  Use execve directly, not execv.
Diffstat (limited to 'posix/execvp.c')
-rw-r--r--posix/execvp.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/posix/execvp.c b/posix/execvp.c
index 3f93357af8..27568294a5 100644
--- a/posix/execvp.c
+++ b/posix/execvp.c
@@ -47,7 +47,7 @@ script_execute (const char *file, char *const argv[])
       }
 
     /* Execute the shell.  */
-    execv (new_argv[0], new_argv);
+    __execve (new_argv[0], new_argv, __environ);
   }
 }
 
@@ -69,7 +69,7 @@ execvp (file, argv)
   if (strchr (file, '/') != NULL)
     {
       /* Don't search when it contains a slash.  */
-      execv (file, argv);
+      __execve (file, argv, __environ);
 
       if (errno == ENOEXEC)
 	script_execute (file, argv);
@@ -93,30 +93,32 @@ execvp (file, argv)
 	}
 
       len = strlen (file) + 1;
-      name = __alloca (strlen (path) + len);
+      name = __alloca (strlen (path) + len + 1);
+      /* Copy the file name at the top.  */
+      name = (char *) memcpy (name - len, file, len);
+      /* And add the slash.  */
+      *--name = '/';
+
       p = path;
       do
 	{
+	  char *startp;
+
 	  path = p;
 	  p = __strchrnul (path, ':');
 
 	  if (p == path)
 	    /* Two adjacent colons, or a colon at the beginning or the end
 	       of `PATH' means to search the current directory.  */
-	    (void) memcpy (name, file, len);
+	    startp = name + 1;
 	  else
-	    {
-	      /* Construct the pathname to try.  */
-	      char *tmp = __mempcpy (name, path, p - path);
-	      *tmp++ = '/';
-	      memcpy (tmp, file, len);
-	    }
+	    startp = (char *) memcpy (name - (p - path), path, p - path);
 
 	  /* Try to execute this name.  If it works, execv will not return.  */
-	  execv (name, argv);
+	  __execve (startp, argv, __environ);
 
 	  if (errno == ENOEXEC)
-	    script_execute (name, argv);
+	    script_execute (startp, argv);
 
 	  switch (errno)
 	    {