Implement xstrdup() using strlen()/xmalloc()/memcpy() already

presented in rtld, instead of pulling in libc strdup().

Submitted by:	   bde
MFC after:	   2 weeks
This commit is contained in:
Konstantin Belousov 2012-03-23 12:04:44 +00:00
parent 3b5683fce6
commit f7b343037f

View File

@ -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);
}