diff options
author | Volker Lendecke <vl@samba.org> | 2021-01-05 10:27:12 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2021-01-12 00:10:30 +0000 |
commit | 8b5eda7535c9f0dcef010e6edeb9deec8a8213a0 (patch) | |
tree | edca577df6f5b7e8a369a36d713888c547a05ccc /lib | |
parent | ae78cf0d61e62f1292af9d713aa8c06b9b379d91 (diff) | |
download | samba-8b5eda7535c9f0dcef010e6edeb9deec8a8213a0.tar.gz |
lib: Move utf16_len[_n]() to lib/util/charset/
util_unistr.c references it, avoid broken dependencies
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/charset/charset.h | 13 | ||||
-rw-r--r-- | lib/util/charset/util_unistr.c | 30 | ||||
-rw-r--r-- | lib/util/samba_util.h | 13 | ||||
-rw-r--r-- | lib/util/util_str.c | 31 |
4 files changed, 43 insertions, 44 deletions
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index 3aa8a812ccc..c62832cccd6 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -95,6 +95,19 @@ 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 +the result includes the null termination +**/ +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 +limited by 'n' bytes +**/ +size_t utf16_len_n(const void *src, size_t n); + char *strchr_m(const char *s, char c); /** * Calculate the number of units (8 or 16-bit, depending on the diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index ed394f58aef..585cb787d09 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -188,6 +188,36 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags) return PTR_DIFF(p, base_ptr) & 1; } +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +**/ +size_t utf16_len(const void *buf) +{ + size_t len; + + for (len = 0; SVAL(buf,len); len += 2) ; + + return len + 2; +} + +/** +return the number of bytes occupied by a buffer in CH_UTF16 format +the result includes the null termination +limited by 'n' bytes +**/ +size_t utf16_len_n(const void *src, size_t n) +{ + size_t len; + + for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ; + + if (len+2 <= n) { + len += 2; + } + + return len; +} /** * Copy a string from a char* unix src to a dos codepage string destination. diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index a8be028e563..f0bfa809d7b 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -313,19 +313,6 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val); _PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val); /** -return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination -**/ -_PUBLIC_ 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 -limited by 'n' bytes -**/ -_PUBLIC_ size_t utf16_len_n(const void *src, size_t n); - -/** * @brief Constant time compare to memory regions. * * @param[in] s1 The first memory region to compare. diff --git a/lib/util/util_str.c b/lib/util/util_str.c index c7773e0c927..da1989f80f2 100644 --- a/lib/util/util_str.c +++ b/lib/util/util_str.c @@ -305,37 +305,6 @@ _PUBLIC_ bool set_boolean(const char *boolean_string, bool *boolean) return false; } -/** -return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination -**/ -_PUBLIC_ size_t utf16_len(const void *buf) -{ - size_t len; - - for (len = 0; SVAL(buf,len); len += 2) ; - - return len + 2; -} - -/** -return the number of bytes occupied by a buffer in CH_UTF16 format -the result includes the null termination -limited by 'n' bytes -**/ -_PUBLIC_ size_t utf16_len_n(const void *src, size_t n) -{ - size_t len; - - for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ; - - if (len+2 <= n) { - len += 2; - } - - return len; -} - _PUBLIC_ int memcmp_const_time(const void *s1, const void *s2, size_t n) { const uint8_t *p1 = s1, *p2 = s2; |