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);
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to