0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 02:18:53 +02:00

ircd::strlcpy: Use character copy; remove branch.

This commit is contained in:
Jason Volk 2020-06-04 18:37:03 -07:00
parent 758ff8c4b7
commit 1ef26f113f

View file

@ -48,13 +48,15 @@ struct ircd::strlcpy
strlcpy(char *const &dst, const string_view &src, const size_t &max)
:ret{[&]() -> mutable_buffer
{
if(!max)
return {};
mutable_buffer buf{dst, max};
const mutable_buffer tgt
{
buf, std::min(size(src), std::max(max, 1UL) - 1UL)
};
const auto len(std::min(src.size(), max - 1));
buffer::copy(mutable_buffer(dst, len), src);
dst[len] = '\0';
return { dst, len };
consume(buf, copy(tgt, src));
consume(buf, copy(buf, '\0'));
return tgt;
}()}
{}