[PATCH 2/3] lib/charset: add u16_strcat() function

Masahisa Kojima masahisa.kojima at linaro.org
Thu Feb 10 08:05:35 CET 2022


Provide u16 string version of strcat().

Signed-off-by: Masahisa Kojima <masahisa.kojima at linaro.org>
---
 include/charset.h | 13 +++++++++++++
 lib/charset.c     | 12 ++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/charset.h b/include/charset.h
index b93d023092..baba9d7c14 100644
--- a/include/charset.h
+++ b/include/charset.h
@@ -259,6 +259,19 @@ u16 *u16_strcpy(u16 *dest, const u16 *src);
  */
 u16 *u16_strdup(const void *src);
 
+/**
+ * u16_strcat() - append u16 string
+ *
+ * Append the src string to the dest string, overwriting the terminating
+ * null word at the end of dest, and then adds a terminating null word.
+ * The dest string must have enough space for the result.
+ *
+ * @dest:		destination buffer (null terminated)
+ * @src:		source buffer (null terminated)
+ * Return:		'dest' address
+ */
+u16 *u16_strcat(u16 *dest, const u16 *src);
+
 /**
  * utf16_to_utf8() - Convert an utf16 string to utf8
  *
diff --git a/lib/charset.c b/lib/charset.c
index f44c58d9d8..f0eaf6c1ae 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -428,6 +428,18 @@ u16 *u16_strdup(const void *src)
 	return new;
 }
 
+u16 *u16_strcat(u16 *dest, const u16 *src)
+{
+	u16 *tmp = dest;
+
+	while (*dest)
+		dest++;
+	while ((*dest++ = *src++) != u'\0')
+		;
+
+	return tmp;
+}
+
 /* Convert UTF-16 to UTF-8.  */
 uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
 {
-- 
2.17.1



More information about the U-Boot mailing list