mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
libdm: optimize dm_pool_strndup
This commit is contained in:
parent
93dfb5dd3e
commit
65eb29503b
@ -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)
|
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);
|
char *ret = dm_pool_alloc(p, n + 1);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
strncpy(ret, str, n);
|
ret[len] = '\0';
|
||||||
ret[n] = '\0';
|
memcpy(ret, str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user