summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/xmalloc.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-03-23 12:04:44 +0000
committerkib <kib@FreeBSD.org>2012-03-23 12:04:44 +0000
commit6355fe9a5c9d3dd34df91e194bb93b4744804ae6 (patch)
treedf3d6bfcebd234818868a70c97411becf9807e8f /libexec/rtld-elf/xmalloc.c
parenta7368abeec243f83cfc54a018e2e3a3ba3a9c5d4 (diff)
downloadFreeBSD-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
Diffstat (limited to 'libexec/rtld-elf/xmalloc.c')
-rw-r--r--libexec/rtld-elf/xmalloc.c15
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);
}
OpenPOWER on IntegriCloud