mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::strlcpy: Use character copy; remove branch.
This commit is contained in:
parent
758ff8c4b7
commit
1ef26f113f
1 changed files with 8 additions and 6 deletions
|
@ -48,13 +48,15 @@ struct ircd::strlcpy
|
||||||
strlcpy(char *const &dst, const string_view &src, const size_t &max)
|
strlcpy(char *const &dst, const string_view &src, const size_t &max)
|
||||||
:ret{[&]() -> mutable_buffer
|
:ret{[&]() -> mutable_buffer
|
||||||
{
|
{
|
||||||
if(!max)
|
mutable_buffer buf{dst, max};
|
||||||
return {};
|
const mutable_buffer tgt
|
||||||
|
{
|
||||||
|
buf, std::min(size(src), std::max(max, 1UL) - 1UL)
|
||||||
|
};
|
||||||
|
|
||||||
const auto len(std::min(src.size(), max - 1));
|
consume(buf, copy(tgt, src));
|
||||||
buffer::copy(mutable_buffer(dst, len), src);
|
consume(buf, copy(buf, '\0'));
|
||||||
dst[len] = '\0';
|
return tgt;
|
||||||
return { dst, len };
|
|
||||||
}()}
|
}()}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue