From patchwork Fri Nov 16 01:18:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151265 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7715231ljp; Thu, 15 Nov 2018 17:17:12 -0800 (PST) X-Google-Smtp-Source: AJdET5cGSoUHEch2LOpzFzp6/UfDEgI1oc8EjdiLHwoA2+EPqKpV4hhZwPO9DnL0oTFbrLn0Wtcg X-Received: by 2002:a50:c21a:: with SMTP id n26-v6mr3410800edf.89.1542331032528; Thu, 15 Nov 2018 17:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542331032; cv=none; d=google.com; s=arc-20160816; b=IqMg9yRMiybvLkVLpU0uHKVgwZj4w0Hg9pbyRn/KY6AsVkJf8OP3i0NZF50CFJN2wP SiUn22QirfRwsJQP1VTx2+UgKfIfAKIiskKayvBEfdb7PW5rIW4h3BEosphsYPcNgxNY BminyP+lvrfUCE5X9q9LP1R8iaQ0TPHj2NaE7u9h7xwdETcdehQZtyQ2HtsFwUD+cScM 47CbKkyoXZWevRJanE6mgGGprwhl+FXFCqjAJJ4LlBeFVBaVQqy1ZbCHhMTVM6TOrciv m9C9f3ps/EEgZWxlzSZze5wZzDMCG0OsYRsGGimGJUyabd3xCCleek5ZTw5Vf4/yLtnX 0u+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=xV+RIlJfGVTqighnv1X4si9JqwXp7YGL+d6GazgdMFQ=; b=FhKNdEP1wQWHIW+EKdrS+mSyXfx8/jYg/RZgafA8wp8q5cWwJvEoDjtXguBg3xTRMz XsTJ1pwXHp5mpbpapyC/hmhCJFXI98QK0nbu9u1U0jwOgAFadh/dtktvPKHfeValQEF3 nS0rNoP2ZXDQX8xB+3qx3gmNOCYVcON2K3vaJxzwYpy2Ckk2xvi24mufsMrQRidrfpFz MNbq1bSUdbbNzJCVFkGvVg0Dysbb7akZtnoQJn5EQ6bhFDTOy9opBs+5vEKrzu/6n2vF p+M9uEmo8ltGnZq8MHfySLCY7BiV2KEzUWxnXmJaKNKjJkYqml8kCgq8cy3N06Cul3eg lvnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c8zWwjt8; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id d4-v6si4269417edc.237.2018.11.15.17.17.12; Thu, 15 Nov 2018 17:17:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c8zWwjt8; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 0E241C22127; Fri, 16 Nov 2018 01:16:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C670BC22251; Fri, 16 Nov 2018 01:16:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 57079C2224A; Fri, 16 Nov 2018 01:16:35 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id 4BF86C2224B for ; Fri, 16 Nov 2018 01:16:32 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id h187-v6so9158260ybg.10 for ; Thu, 15 Nov 2018 17:16:32 -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 :mime-version:content-transfer-encoding; bh=QlBL5k8ko5+7ihZJOIvAZwrPCxBuECoUCMBD/bXswQQ=; b=c8zWwjt8bOlAUKO+KAe9GV9ru5M7IWw7aGK/ZO+11pKh3+kRu8bGQkc8SAon0/ynWv Sfqv5QtoT4ch8rcNkRxeWRvGqz7I47HTeSJ27VutemQJB4l4+MzwctGFf10rEw5I4ICZ /vqECUB9u/BGl4d78jeYWGA4OiUK0Fsaq0iKw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QlBL5k8ko5+7ihZJOIvAZwrPCxBuECoUCMBD/bXswQQ=; b=Tm0objeh8UBzZZuK4/zeDfn17gXAT8Kki0y++HkoHmO3SkvfkTzLgnZNgcH+uczzml j2gfxhOsulyEuaV9b5KA0xPuX/jR3KzssFzomHhByf9MonuqUTAe0vVxFcH25I/S1d1x DqZU63wEW5iutYywh8Bd8boqhBEQCPqGs1yFT1KO/PNOwundUwsKUTT+CS2eQ5B0Yy20 eAGH7s0tLAGemzGkhX2AP1isgPQNoCkGj45TerEvNyv+s/si3O7vOPS97XmuAlB8FpGq Wks5wh+Bcwkbw4jkIUYXDvJMGg8AvSS6TUBBz39qm6rzNbERMFRH1t3esYd5b+m7pqMp UEKw== X-Gm-Message-State: AGRZ1gKuOZ6raLN+gR6vMPeeosk9AgoJwKF3YEWErLN6vDxp9ggvmqiy Otrhj2n5q3SyIgfsWKxNtlx9gA== X-Received: by 2002:a25:68ca:: with SMTP id d193-v6mr8563024ybc.179.1542330991008; Thu, 15 Nov 2018 17:16:31 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l8-v6sm6915660ywl.11.2018.11.15.17.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 17:16:30 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Fri, 16 Nov 2018 10:18:32 +0900 Message-Id: <20181116011837.27542-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181116011837.27542-1-takahiro.akashi@linaro.org> References: <20181116011837.27542-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/6] lib: add u16_strcpy/strdup functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" From: "Akashi, Takahiro" Add u16_strcpy() and u16_strdup(). The latter function will be used later in implementing efi HII database protocol. Signed-off-by: Akashi Takahiro --- include/charset.h | 23 +++++++++++++++++++++++ lib/charset.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/charset.h b/include/charset.h index 4d45e246e515..65087f76d1fc 100644 --- a/include/charset.h +++ b/include/charset.h @@ -191,6 +191,29 @@ size_t u16_strlen(const u16 *in); */ size_t u16_strnlen(const u16 *in, size_t count); +/** + * u16_strcpy() - copy u16 string + * + * Copy u16 string pointed to by src, including terminating null word, to + * the buffer pointed to by dest. + * + * @dest: destination buffer + * @src: source buffer (null terminated) + * Return: 'dest' address + */ +u16 *u16_strcpy(u16 *dest, const u16 *src); + +/** + * u16_strdup() - duplicate u16 string + * + * Copy u16 string pointed to by src, including terminating null word, to a + * newly allocated buffer. + * + * @src: source buffer (null terminated) + * Return: allocated new buffer on success, NULL on failure + */ +u16 *u16_strdup(const u16 *src); + /** * utf16_to_utf8() - Convert an utf16 string to utf8 * diff --git a/lib/charset.c b/lib/charset.c index 10557b9e753d..5e349ed5ee45 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -349,6 +349,35 @@ size_t u16_strnlen(const u16 *in, size_t count) return i; } +u16 *u16_strcpy(u16 *dest, const u16 *src) +{ + u16 *tmp = dest; + + for (;; dest++, src++) { + *dest = *src; + if (!*src) + break; + } + + return tmp; +} + +u16 *u16_strdup(const u16 *src) +{ + u16 *new; + + if (!src) + return NULL; + + new = malloc((u16_strlen(src) + 1) * sizeof(u16)); + if (!new) + return NULL; + + u16_strcpy(new, src); + + return new; +} + /* Convert UTF-16 to UTF-8. */ uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size) {