From patchwork Tue Feb 22 16:02:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 545042 Delivered-To: patch@linaro.org Received: by 2002:adf:a34a:0:0:0:0:0 with SMTP id d10csp367378wrb; Tue, 22 Feb 2022 08:01:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcRAfl5knAfth4tQACnWi3JuDpp7dNp0et7zO4zapyvaw8iUXF61CdEF2czJpXXRj8EO53 X-Received: by 2002:aa7:d1d7:0:b0:410:d6cf:82b2 with SMTP id g23-20020aa7d1d7000000b00410d6cf82b2mr26394785edp.193.1645545692745; Tue, 22 Feb 2022 08:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645545692; cv=none; d=google.com; s=arc-20160816; b=FkDN9XhduffYZ4EsDxieGhG2O368Lix2C4AxsbK0pQIPeQ238jMy6OnuaX63yzV3nz 6fg8Z/OVr9rJnKEvILUtbHmSdcikOCkmqWzfQFi3910umQ+3Yb4K5pL/OYB4tY+n4hGX 9ynnNcuA/6YQQ2KtDSDVy+wYlitoSfBlHjmNYIIzfSLCLA4nJWWfRzMxNh/np76qxyEH Lvb5V0mgSe1d8zgxd7dQBsMrTVj8oB3zHQAhhZ3R0dzhFy2R3XdZWRNi7Rwp/rUfIb6j ju9iGghdU6fFZOnGskd4i8j9pR/XmSOHdsy51sKifopSEDWXJybRGnVIJxxfw5toNZ+g lEGA== 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=YjLWLkI9dx/+b3AO9YTN331wQL8RFtpfwx867EHnL1U=; b=WfaXIg1ZGxvD06pp3xpG13OKdplP7mHj1aZTqimB1Uyyk4PY72CBAgqKieqhRL1GWr mNYCL5CETHpv++L7/3+SHPV/friIm4ntvfdZTXqRkz5DjWO8YLitsnA95zjrrJwBtZkF nxR1mUato4BdnfTaCNjfEZW/28dQLjNmu2undka49s5snzVgqPwQQhcBxdPSZStEXdwk nv9yslGIaxiniO6dH+h/zfo9PYKFA376rvoS1/IIjPjkhfQuDF4lfKSFnHq3PT9SFBBY AZ48HJQfl9UOPbZBYWvBeCfOCNEIQDaQTp/ItUsl99I3st4UfKRqAv5OqtnE8YcsLeor v1ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i0SJbLJ4; 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 ji20si12812109ejc.147.2022.02.22.08.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 08:01:32 -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=i0SJbLJ4; 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 D0A5683CA1; Tue, 22 Feb 2022 17:01:26 +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="i0SJbLJ4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C4C1483C95; Tue, 22 Feb 2022 17:01:24 +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-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 5B9BF83C97 for ; Tue, 22 Feb 2022 17:01:20 +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-x632.google.com with SMTP id w20so15980095plq.12 for ; Tue, 22 Feb 2022 08:01:20 -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=YjLWLkI9dx/+b3AO9YTN331wQL8RFtpfwx867EHnL1U=; b=i0SJbLJ4+4bS69xZGG1p0fPFCy3jSjiirle8apPtHZDK6zmLH2FfvsKlCe+btzDw7f IFA8BLi2ZwJLN8QqD9fZ5T8r+8LW0/3IjH7wrNz9ZVdlgpdVfyew11Ns56NDC6ChMBXr pjYRVkrnmQfboPhfZ0y+1TF/4VvND/+cXj5wQ873b7YZVQNfwAr/FY2rWCJdRG+CiSMX z7CC85z6A3vyyiWZGfSrEpVWY5YQ8bPVPz5qGzr5axwox4H0NeAoHWsLMgql5VJtFFTq z38RIjxwOlqrjK9p1fHD+cohBxRAl5MJoBHrIY4skV8G4t/bjphgpW5KvXj0MZCU5TBA UX2w== 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=YjLWLkI9dx/+b3AO9YTN331wQL8RFtpfwx867EHnL1U=; b=1FLH0QrVFG5YRVwcyiGQfgL9tZuhSMYi/yxmR5moILEbGICVe5NbJZZtluEYxa2XaB PqzO2k4nIrYki5rYTVSDx11SlHiXgJzSFZDUNs9S5hxr60hjaNlu51nnPN6IR0Tk9xVs iOWu8KKxUQ6xV6v7wgtzCrJzRrMQAdD9ezpBoDU+xzDvYJq3vnExFkvWDAirlfyqV4A/ UKb/7UdG6SJ49ITLmA7IESi4BTfc0i7TzYWTXmd6AnZC8SveA/2bGXBwz5jbUI6C13P/ aIGWdd+p7iBTp3+RcwfP+fTxNh8wN7eOqk7Fv24B11Rq5lNb1xDZfT8uruzC6EkLD2I/ OhUA== X-Gm-Message-State: AOAM533x/DltOihDeDxGwTMwV6BawUu2p51GuXR0HF6001JaZ1ANj+S4 U67vdMtHIGitfxZrl0RkPV04MC6Hyh/27w== X-Received: by 2002:a17:90a:eb93:b0:1bb:8ad9:5b79 with SMTP id o19-20020a17090aeb9300b001bb8ad95b79mr4797254pjy.215.1645545678705; Tue, 22 Feb 2022 08:01:18 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h6sm3017683pjs.30.2022.02.22.08.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 08:01:18 -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: [RFC PATCH v2 2/4] lib/charset: add u16_strlcat() function Date: Wed, 23 Feb 2022 01:02:33 +0900 Message-Id: <20220222160235.24748-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220222160235.24748-1-masahisa.kojima@linaro.org> References: <20220222160235.24748-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 --- 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) {