1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

libdm: optimize dm_pool_strndup

This commit is contained in:
Zdenek Kabelac 2018-12-01 00:35:41 +01:00 committed by David Teigland
parent 484fb43584
commit 2fc9a4c291

View File

@ -59,11 +59,13 @@ char *dm_pool_strdup(struct dm_pool *p, const char *str)
char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n)
{
size_t slen = strlen(str);
size_t len = (slen < n) ? slen : n;
char *ret = dm_pool_alloc(p, n + 1);
if (ret) {
strncpy(ret, str, n);
ret[n] = '\0';
ret[len] = '\0';
memcpy(ret, str, len);
}
return ret;