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: 998665 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="c8zWwjt8"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42x0hL3qdmz9sB5 for ; Fri, 16 Nov 2018 12:17:22 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2EF5CC221C6; 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-Google-Smtp-Source: AJdET5drXtkfrjfAhxqfjqjk98WwOzUIS02xNNgxqGgcPwprx5Qltal0XiLl1xgdhdUC6/gxLJC/Lg== 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) {