util/charset: Add utf16_len()
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 8 Nov 2023 23:39:02 +0000 (12:39 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 15 Nov 2023 22:07:36 +0000 (22:07 +0000)
This function returns the length in bytes of a UTF‐16 string excluding
the null terminator.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/charset/charset.h
lib/util/charset/util_unistr.c

index f350e748c07911e367051fe9c2cda19e9de92a2f..0f3c6750a4fa5b82e1818992962f248d87169013 100644 (file)
@@ -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
index c94068819ce74c17a4742e1cdec425a7b3c2346a..d81a9c3b70f0d33f47b60b1f92f574156d64aa20 100644 (file)
@@ -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;
 }
 
 /**