diff options
Diffstat (limited to 'usr/src/lib/libdemangle/common/util.c')
-rw-r--r-- | usr/src/lib/libdemangle/common/util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/usr/src/lib/libdemangle/common/util.c b/usr/src/lib/libdemangle/common/util.c index 9ffb72c79b..739c554826 100644 --- a/usr/src/lib/libdemangle/common/util.c +++ b/usr/src/lib/libdemangle/common/util.c @@ -11,6 +11,7 @@ /* * Copyright 2017 Jason King + * Copyright 2019, Joyent, Inc. */ #include <sys/debug.h> @@ -71,6 +72,20 @@ xrealloc(sysdem_ops_t *ops, void *p, size_t oldsz, size_t newsz) return (temp); } +char * +xstrdup(sysdem_ops_t *ops, const char *src) +{ + size_t len = strlen(src); + char *str = zalloc(ops, len + 1); + + if (str == NULL) + return (NULL); + + /* zalloc(len+1) guarantees this will be NUL-terminated */ + (void) memcpy(str, src, len); + return (str); +} + /*ARGSUSED*/ static void def_free(void *p, size_t len) |