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)
|
||||
: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;
|
||||
}()}
|
||||
{}
|
||||
|
||||
|
|
Loading…
Reference in a new issue