From: Joseph Sutton Date: Wed, 8 Nov 2023 23:39:02 +0000 (+1300) Subject: util/charset: Add utf16_len() X-Git-Tag: talloc-2.4.2~681 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=516f35b5a114136eaae283a53a6281b9895e29ed;p=thirdparty%2Fsamba.git util/charset: Add utf16_len() This function returns the length in bytes of a UTF‐16 string excluding the null terminator. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index f350e748c07..0f3c6750a4f 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -103,6 +103,11 @@ struct smb_iconv_handle; size_t ucs2_align(const void *base_ptr, const void *p, int flags); +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +**/ +size_t utf16_len(const void *buf); + /** return the number of bytes occupied by a buffer in CH_UTF16 format the result includes the null termination diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index c94068819ce..d81a9c3b70f 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -193,15 +193,23 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags) /** return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination **/ -size_t utf16_null_terminated_len(const void *buf) +size_t utf16_len(const void *buf) { size_t len; for (len = 0; SVAL(buf,len); len += 2) ; - return len + 2; + return len; +} + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +**/ +size_t utf16_null_terminated_len(const void *buf) +{ + return utf16_len(buf) + 2; } /**