1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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 <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton 2023-11-09 12:39:02 +13:00 committed by Andrew Bartlett
parent 16996d145b
commit 516f35b5a1
2 changed files with 16 additions and 3 deletions

View 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

View 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;
}
/**