From patchwork Fri Feb 25 01:32:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 545898 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp733160imj; Thu, 24 Feb 2022 17:32:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJycDdvY//KqPkHOCz0lf8trhSOM1E7evdvrwxVbgPqbTcKSkLnxEWmiqupqqWuHbrADtvf9 X-Received: by 2002:a17:906:3152:b0:6cf:d100:a8b2 with SMTP id e18-20020a170906315200b006cfd100a8b2mr4305735eje.529.1645752732760; Thu, 24 Feb 2022 17:32:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645752732; cv=none; d=google.com; s=arc-20160816; b=pUOD3QlLxHDzuk2GkEyZPWFvT5cHwrcyTEawD+VGcVFWUwFw4+Rnn/PtrglQGIirnT RK74viMA1kI60VGESqbpx6GOhw/xdLUzNvv5/2f2GQ6jh7IW6QNBOWkrOnC+fcnN3uoi 2ebh1cRXqhJM9uF2BcuI60vbOQuGJ4HxDQF7+YQ+INBi5zxaEQoG8xZBP97/9WLypPMn bjBQ6zZHDN6NMiNuCOhD0E924gHUuA/BpMrmeVSJLTFQ2Jp8GAue8+jNpJAr0ewFcw3A gnisDMmOYlXB2uLNEH8JS3DMwOzIvLNy++5xO0ClUXV/F6pKrOR/MtkehWn9WfOmZNs+ cgbw== 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=nSWSSNPaMb0JBMyST5ZRyhlIlspmweXsGYsc0qcMxjE=; b=APRCXYlhT5SE1DXfWhzdKs1+9r/cFoU3fdaUUwLR+tzstgu7VJ2L4YMw/ulAiZQotO XZTjXF/PHk5LTE/cYdnpN5900ddXzWS7TVOwK5oJUOcQ/eHh+BYmpupHrnseDa/xlLws ck/7PkOCmS69XBEif8BGY9yNUhgPJ6x3FHgFUNJRNdFEumEW00hmjMSNfofvdiWjfqnE 0n4Kpvz6M/owvE3Okp39RY/lLUUK49bmz2b0A/IkL20QXxlOEZJHZojxIwxs+Co5/wme ZSiW0/oYJRs5L7LF7L5oYYMF1fdWV3O/L0rifRz2J1yN6QKIau8K4xEJA0tiX7qrJCnx McrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K2bWF4lB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id c26-20020a056402143a00b00412b6b680ffsi768452edx.412.2022.02.24.17.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 17:32:12 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K2bWF4lB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 BA16683CDE; Fri, 25 Feb 2022 02:32:06 +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="K2bWF4lB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A22B583CB1; Fri, 25 Feb 2022 02:31:48 +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-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 B65C583C6A for ; Fri, 25 Feb 2022 02:31:43 +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-x62f.google.com with SMTP id i1so3462455plr.2 for ; Thu, 24 Feb 2022 17:31:43 -0800 (PST) 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=nSWSSNPaMb0JBMyST5ZRyhlIlspmweXsGYsc0qcMxjE=; b=K2bWF4lBwXj2T1k4kZkEaMdvub0t3G34bcSMej7pyimODq6mXkOiA00srF/A5eRbYH FI6dvu2EHzpY1lV2mmt2jEIIjaDoJveXZ8jKPsHF/gH/UYdFswMpvzXcM5vklaAAnB9s YNdDl0FgVG0eV1r1GGr3mx7xcBPvFbogRkh/fwXiwog48Xa67sUbJLbwylQmGNOhLhg7 fU6OG6YdzNwcdspq1PUsnCY92VIuHKtAIxRsmd9sOERKDYMS0NuaQ0NoSLcRn7h9PtQX m8IlFlFmK8hyZ9LwV4pTWh8Qbo8XkRqI2NFGgLXpt6srrTFIz558x56LLj/9Btrrynup nNCA== 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=nSWSSNPaMb0JBMyST5ZRyhlIlspmweXsGYsc0qcMxjE=; b=fkj5WyzmUHHxhoDM7ujHhI2OLGc6zmISc3CYnKLvlbpewbX9n5Sitsk8frsbnsyPij DOihoVHL8ul8pjKTyKL2hTI8VZ1b57d/wOdZQ2SLZMPp8YqZbMP8i7nXpT31RY81oLLy CS3dz+/fIsBjaEUf3G69X9bmKUoM5Qe1UuDyvfvmo8c0J2bFewCDVUS4MOrujk1zeD6G pGMQ2zrSdS24XwPzVZRUbTavv2nfzCZbVnUuAg0jsJ+sEnilJYmoupqsX/vKhZ1yvgPT UWjh1xcaGujGqY2eRgtJKM9vNW9HYXJJI0sU5MpzmDkBhsbNINeQXZ8ZXuBtIzJySa0f +Ogw== X-Gm-Message-State: AOAM5302h5KTaQa945TBn21pUT5aIVLlDDMuuSRJ3mds/FhOvgeE5k3c 5VNbs9gV9oeZkQqpXWVtaFzrRxGrCeu/OA== X-Received: by 2002:a17:902:cec3:b0:14f:f2e3:df52 with SMTP id d3-20020a170902cec300b0014ff2e3df52mr4935528plg.64.1645752702029; Thu, 24 Feb 2022 17:31:42 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id n18-20020a056a00213200b004e17d967d13sm703888pfj.124.2022.02.24.17.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 17:31:41 -0800 (PST) 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: [RESEND RFC PATCH v2 2/4] lib/charset: add u16_strlcat() function Date: Fri, 25 Feb 2022 10:32:55 +0900 Message-Id: <20220225013257.15674-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220225013257.15674-1-masahisa.kojima@linaro.org> References: <20220225013257.15674-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 v2: - implement u16_strlcat(with the destination buffer size in argument) instead of u16_strcat include/charset.h | 15 +++++++++++++++ lib/charset.c | 20 ++++++++++++++++++++ 2 files changed, 35 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..f15d5df19a 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -428,6 +428,26 @@ 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) {