From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ilias Apalodimas Date: Wed, 6 May 2020 22:12:41 +0300 Subject: [PATCH 1/6] charset: Add support for calculating bytes occupied by a u16 string In-Reply-To: <20200506191246.237790-1-ilias.apalodimas@linaro.org> References: <20200506191246.237790-1-ilias.apalodimas@linaro.org> Message-ID: <20200506191246.237790-2-ilias.apalodimas@linaro.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Sughosh Ganu The current code uses 'u16_strlen(x) + 1) * sizeof(u16)' in various places to calculate the number of bytes occupied by a u16 string. Let's introduce a wrapper around this. This wrapper is used on following patches Signed-off-by: Sughosh Ganu --- include/charset.h | 11 +++++++++++ lib/charset.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/charset.h b/include/charset.h index fde6bddbc2fb..30faa72285e6 100644 --- a/include/charset.h +++ b/include/charset.h @@ -195,6 +195,17 @@ int u16_strncmp(const u16 *s1, const u16 *s2, size_t n); */ size_t u16_strlen(const void *in); +/** + * u16_strsize - count size of u16 string in bytes including the null character + * + * Counts the number of bytes occupied by a u16 string + * + * @in: null terminated u16 string + * Return: bytes in a u16 string + * + */ +size_t u16_strsize(const void *in); + /** * u16_strlen - count non-zero words * diff --git a/lib/charset.c b/lib/charset.c index 1c6a7f693de4..a28034ee1f1e 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -379,6 +379,11 @@ size_t u16_strnlen(const u16 *in, size_t count) return i; } +size_t u16_strsize(const void *in) +{ + return (u16_strlen(in) + 1) * sizeof(u16); +} + u16 *u16_strcpy(u16 *dest, const u16 *src) { u16 *tmp = dest; -- 2.26.2