From patchwork Thu Mar 24 13:54:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 553913 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4438083mag; Thu, 24 Mar 2022 06:55:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0X0DXo9YNIdJtrJBY/s5h9xR/EiLY5kwkn6P+Hb/tsrgRTxEzaG0h5SjQQ+cyYUJ4LiyO X-Received: by 2002:a17:906:b1d0:b0:6cd:fa02:b427 with SMTP id bv16-20020a170906b1d000b006cdfa02b427mr5814337ejb.99.1648130113418; Thu, 24 Mar 2022 06:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648130113; cv=none; d=google.com; s=arc-20160816; b=xgs9SSD+q0UslubjamBeZo4tx6ydwBTQHfIh/ETvvOjkeEnd43vQfrvQ5ZylBTxq5H fGUqSh3v5aHiixE45GGykdYhn81yujNiQtu5wEiSqOh+Njy7nOu8KHspnJxgBDrjjKiC 14gqzAbx12CjsVzuOqyXGYLdJV16QSIKXzI/rvMJNhwx/Ynxbpu3i+gdpiP1iDX96Wlc 78b+2XQr3Wb+nPKPEyZ3qKhcpsCTNDUe0zSKkLifLqpyYMXGnZh3Sa/D/XGFNQB5kZ16 cs3cXV+2qcKe9/qGsfMaNvVno2Q6m7m41U2lfxxCAYZQevicWTWa+BZJIGbCWSV9+6cX DaJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=YHAVowG0AofRG7/Ws+4OdImSbygNMfErEAZyDcKG+Fo=; b=YGUANfaMGyiTxBVO4vciXtvxMWeNZAS1hKCOcc8S7PFm+hdWsL9pVy6j4otB22ObGS Uxuh8zeQ/mxAxmvbvD6BXDJWghJqxHaUlMeLxdWpmIGxD7s16m2pkN3XfZN2oY0cz7bf guNPPsmwrqoHsl9eS5stOP7hAw32RhN6sAy2i1nx4DM+jIKHbDqRxDGfqyoKR205KJHP 5VUVWk5GPlL5KhFX9ejTGSRkja+Y/wfBcgk+d5jDllZt9Ubs58NlhFlcvN2HIaqGCLUd VDmoNY5txINWPlFuymejJNUued7PyKVv+B0125iGY6Pu6KJQ7BIoVyBT8afMB6bQE+rG QgHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a9ukwrf3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id fb15-20020a1709073a0f00b006df7a784b52si13887950ejc.508.2022.03.24.06.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:55:13 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a9ukwrf3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 50145840B2; Thu, 24 Mar 2022 14:54:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="a9ukwrf3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDEE3840B3; Thu, 24 Mar 2022 14:54:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CED0F840A1 for ; Thu, 24 Mar 2022 14:54:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62d.google.com with SMTP id g3so4754216plo.6 for ; Thu, 24 Mar 2022 06:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YHAVowG0AofRG7/Ws+4OdImSbygNMfErEAZyDcKG+Fo=; b=a9ukwrf3MX7Xh+RpBv7WyyVGofgMPpi7jVL2mUKFafzrhzaIJNjb6eA3SlojR9Zd2F rSEHozP7CkZSbxCK5HzRWzajScsxA67kXv/YUzssT9IW3NupwBaoI9wEU20rSDE9xeb5 QHGxJethZQI5y3lH0IKIQ3dv5+L6+WSErdKZrcIvnEZvUFiPy1oMX8qkMSTGXBAw9WzF HEfpM2eMbcdx62CU4ijuxHtMPfSTAgc0zpu1Ng6MaaSsf8n6kPomPnRRK1lemAV/JPhV jqc31DDplmrZ1fchliuSAdrir9lXFE1v10Yy+28yadUMFuNuPW7Rwsb6wBYO4oe/ZvQZ eK4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YHAVowG0AofRG7/Ws+4OdImSbygNMfErEAZyDcKG+Fo=; b=2yw++xPEHBDcAIgR8cl9Sj433J4+250rY511bTl4XWRYN1SAcIuDxkJUdLRgKdmECF Z/nnab8FFhCFbzJ8feA3zacE/+wQJT5RW5phsF/ngiPAJ8zleGzGFny5iVr6mR+6Z9Hn kqWZi12CUV3bm0+9XOseHKBQ6XGiJuC47bE8KkY9z3/rQLNjTfyB+IDqI0THZOK0QorD KAOYlE3j06yhCmTaooTqW9rrpQzNCGg9iCaHD9RplFJ/gBHymHE2n6rKm4tlMmB6kVOl fFebMFKecJefaOqkt+aQ3n1f5uWxCgGHAS76W7HwKUPbfoF9jql6oFSuLgIQQnIC7IE7 LMlw== X-Gm-Message-State: AOAM531UPqhcdUzs2AUTwUjrtSp88u2nKKSyowvRsvlkcw8NQ2adGSNY SlYruyYSYGZ57IJlUQuWYHkY4fqOirkQ+w== X-Received: by 2002:a17:902:7d93:b0:14d:d401:f59b with SMTP id a19-20020a1709027d9300b0014dd401f59bmr6148908plm.14.1648130083120; Thu, 24 Mar 2022 06:54:43 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id p15-20020a056a000a0f00b004f7c63cba5asm3974609pfh.21.2022.03.24.06.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:54:42 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v4 02/11] lib/charset: add u16_strlcat() function Date: Thu, 24 Mar 2022 22:54:34 +0900 Message-Id: <20220324135443.1571-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220324135443.1571-1-masahisa.kojima@linaro.org> References: <20220324135443.1571-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Provide u16 string version of strlcat(). Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass --- Changes in v4: - add blank line above the return statement Changes in v2: - implement u16_strlcat(with the destination buffer size in argument) instead of u16_strcat include/charset.h | 15 +++++++++++++++ lib/charset.c | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/charset.h b/include/charset.h index b93d023092..dc5fc275ec 100644 --- a/include/charset.h +++ b/include/charset.h @@ -259,6 +259,21 @@ u16 *u16_strcpy(u16 *dest, const u16 *src); */ u16 *u16_strdup(const void *src); +/** + * u16_strlcat() - Append a length-limited, %NUL-terminated string to another + * + * 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. + * It will append at most size - u16_strlen(dst) - 1 bytes, NUL-terminating the result. + * + * @dest: destination buffer (null terminated) + * @src: source buffer (null terminated) + * @size: destination buffer size in bytes + * Return: total size of the created string in bytes. + * If return value >= size, truncation occurred. + */ +size_t u16_strlcat(u16 *dest, const u16 *src, size_t size); + /** * utf16_to_utf8() - Convert an utf16 string to utf8 * diff --git a/lib/charset.c b/lib/charset.c index f44c58d9d8..47997eca7d 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -428,6 +428,27 @@ u16 *u16_strdup(const void *src) return new; } +size_t u16_strlcat(u16 *dest, const u16 *src, size_t size) +{ + size_t dstrlen = u16_strnlen(dest, size >> 1); + size_t dlen = dstrlen * sizeof(u16); + size_t len = u16_strlen(src) * sizeof(u16); + size_t ret = dlen + len; + + if (dlen >= size) + return ret; + + dest += dstrlen; + size -= dlen; + if (len >= size) + len = size - sizeof(u16); + + memcpy(dest, src, len); + dest[len >> 1] = u'\0'; + + return ret; +} + /* Convert UTF-16 to UTF-8. */ uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size) {