Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Mar 2012 12:04:44 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r233357 - head/libexec/rtld-elf
Message-ID:  <201203231204.q2NC4iTW075376@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Mar 23 12:04:44 2012
New Revision: 233357
URL: http://svn.freebsd.org/changeset/base/233357

Log:
  Implement xstrdup() using strlen()/xmalloc()/memcpy() already
  presented in rtld, instead of pulling in libc strdup().
  
  Submitted by:	   bde
  MFC after:	   2 weeks

Modified:
  head/libexec/rtld-elf/xmalloc.c

Modified: head/libexec/rtld-elf/xmalloc.c
==============================================================================
--- head/libexec/rtld-elf/xmalloc.c	Fri Mar 23 12:02:00 2012	(r233356)
+++ head/libexec/rtld-elf/xmalloc.c	Fri Mar 23 12:04:44 2012	(r233357)
@@ -57,12 +57,13 @@ xmalloc(size_t size)
 }
 
 char *
-xstrdup(const char *s)
+xstrdup(const char *str)
 {
-    char *p = strdup(s);
-    if (p == NULL) {
-	 rtld_fdputstr(STDERR_FILENO, "Out of memory\n");
-	 _exit(1);
-    }
-    return p;
+	char *copy;
+	size_t len;
+
+	len = strlen(str) + 1;
+	copy = xmalloc(len);
+	memcpy(copy, str, len);
+	return (copy);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203231204.q2NC4iTW075376>