0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 08:42:34 +01:00

ircd: Add string_view strlcat().

This commit is contained in:
Jason Volk 2017-09-12 10:07:14 -07:00
parent 6aacf73dfa
commit b9f6871f1b

View file

@ -602,6 +602,25 @@ ircd::strlcat(char *const &dest,
}
#endif
inline size_t
ircd::strlcat(char *const &dest,
const string_view &src,
const size_t &max)
{
if(!max)
return 0;
const ssize_t dsize(strnlen(dest, max));
const ssize_t ssize(src.size());
const ssize_t ret(dsize + ssize);
const ssize_t remain(max - dsize);
const ssize_t cpsz(ssize >= remain? remain - 1 : ssize);
char *const ptr(dest + dsize);
memcpy(ptr, src.data(), cpsz);
ptr[cpsz] = '\0';
return ret;
}
struct ircd::iless
{
using is_transparent = std::true_type;