diff options
author | kib <kib@FreeBSD.org> | 2012-03-23 12:04:44 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-03-23 12:04:44 +0000 |
commit | 6355fe9a5c9d3dd34df91e194bb93b4744804ae6 (patch) | |
tree | df3d6bfcebd234818868a70c97411becf9807e8f | |
parent | a7368abeec243f83cfc54a018e2e3a3ba3a9c5d4 (diff) | |
download | FreeBSD-src-6355fe9a5c9d3dd34df91e194bb93b4744804ae6.zip FreeBSD-src-6355fe9a5c9d3dd34df91e194bb93b4744804ae6.tar.gz |
Implement xstrdup() using strlen()/xmalloc()/memcpy() already
presented in rtld, instead of pulling in libc strdup().
Submitted by: bde
MFC after: 2 weeks
-rw-r--r-- | libexec/rtld-elf/xmalloc.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c index 3783685..178f49b 100644 --- a/libexec/rtld-elf/xmalloc.c +++ b/libexec/rtld-elf/xmalloc.c @@ -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); } |