summary refs log tree commit diff
path: root/sysdeps/unix
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-02-02 20:17:54 +0000
committerUlrich Drepper <drepper@redhat.com>2002-02-02 20:17:54 +0000
commit88794e308552d6051453544f8790986314fd9e1c (patch)
tree7811ea4e234dd21b1a49424ecfaaf95bda52e7b6 /sysdeps/unix
parent1e823b7d2dcbffb793be1e48b397d7c1a1b19a52 (diff)
downloadglibc-88794e308552d6051453544f8790986314fd9e1c.tar.gz
glibc-88794e308552d6051453544f8790986314fd9e1c.tar.xz
glibc-88794e308552d6051453544f8790986314fd9e1c.zip
Update.
	* elf/dl-object.c (_dl_new_object): Avoid using strrchr.  We have
	more information.
	* elf/rtld.c (dl_main): Avoid strrchr.
	* sysdeps/unix/sysv/linux/dl-origin.c (_dl_get_origin): Use the
	result of readlink.  Search from the back for '/'.
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/dl-origin.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-origin.c b/sysdeps/unix/sysv/linux/dl-origin.c
index 90add58ef5..b054ae2157 100644
--- a/sysdeps/unix/sysv/linux/dl-origin.c
+++ b/sysdeps/unix/sysv/linux/dl-origin.c
@@ -18,6 +18,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -35,19 +36,22 @@ _dl_get_origin (void)
 {
   char linkval[PATH_MAX];
   char *result;
+  int len;
 
-  if (__readlink ("/proc/self/exe", linkval, PATH_MAX) != -1
+  if ((len = __readlink ("/proc/self/exe", linkval, PATH_MAX)) > 0
       && linkval[0] != '[')
     {
       /* We can use this value.  */
-      char *last_slash = strrchr (linkval, '/');
-      result = (char *) malloc (last_slash - linkval + 1);
+      assert (linkval[0] == '/');
+      while (len > 1 && linkval[len - 1] != '/')
+	--len;
+      result = (char *) malloc (len + 1);
       if (result == NULL)
 	result = (char *) -1;
-      else if (last_slash == linkval)
+      else if (len == 1)
 	memcpy (result, "/", 2);
       else
-	*((char *) __mempcpy (result, linkval, last_slash - linkval)) = '\0';
+	*((char *) __mempcpy (result, linkval, len - 1)) = '\0';
     }
   else
     {
@@ -57,7 +61,7 @@ _dl_get_origin (void)
       if (GL(dl_origin_path) != NULL)
 	{
 	  size_t len = strlen (GL(dl_origin_path));
-	  result = malloc (len + 1);
+	  result = (char *) malloc (len + 1);
 	  if (result == NULL)
 	    result = (char *) -1;
 	  else