From patchwork Thu Nov 1 04:45:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149923 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp346927ljp; Wed, 31 Oct 2018 21:43:14 -0700 (PDT) X-Google-Smtp-Source: AJdET5eXjiEL0MgpUeopgWMT+01eIluUKj6MoR8/lqYCvGfmjXxZdGfXj5X/a3L2gr4MfDYlY/Rv X-Received: by 2002:a50:e3c4:: with SMTP id c4-v6mr3472318edm.20.1541047394446; Wed, 31 Oct 2018 21:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541047394; cv=none; d=google.com; s=arc-20160816; b=POciLm5kNodebJyIbLS5QReCFDLJ1v8aJxWpofkzop2Ha7eS/VSsosn3Gf5/xIttDR /bRuyJ0xnsAvG3O1K8V2QdGVvjqSdyeHqxrrc5GRDT167A1Cj1gk4fj7TMpVcvUClpt2 W32t5HEM7h8FxDR3cnd4KYoQRAgqboJSul20wH+Y6Bnpwn0P8HmbNCJncuxjANxbHwGG dPaMyl9//7hTOvZw1CzaQkZWQqCLGPwjQDpqC+ENrNl4lkVUaX9Zmi72fkvPAKC6mtx9 2uDXgvilyUFVRRwP98yiGzoleLIBOU4ZyjSrSnfLj9TACG2JeckTJPWsuSwL8LQ4aSd+ ht/g== 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=Lr9Q1672C+G9kHhelZ8GEWzNq0xuJwF6bcjGrl1ncY8=; b=zNuJxodipc/6+QTVIW+pccgNyWUz0x3SzSVoTY4reBbcbc4setFFjSCmi13JOojoov HC7oBUOaTumiLMrQWsfTKGneIl4EefsxalfZvjOUda0PC7NSwDdWNgQD1nSaiaY+1h9c Pcf8d29OUwcXwRI5tDh/tGjfN4Sp5TDqOSYQBwgThMj2wqcumivWRaajaWQWOwAWFsal 9AVY32bC+V25C7WXSpnVZjywHlJjtxIxVdO1cadoWQvIMSRDaTDzAFgbShufXqo+7tvq EtMgpgUm9vsBILkpB0ug97qSyzL1WkfodMZPidAVNYlqotE+etdjGyLLC1mOjbAJgQ9B j9hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JJsE0oge; 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 c9-v6si7147963edr.216.2018.10.31.21.43.14; Wed, 31 Oct 2018 21:43:14 -0700 (PDT) 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=JJsE0oge; 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 12546C22332; Thu, 1 Nov 2018 04:43:10 +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 ECD00C222D9; Thu, 1 Nov 2018 04:43:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BD5F8C222D9; Thu, 1 Nov 2018 04:43:06 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id 2DD27C22045 for ; Thu, 1 Nov 2018 04:43:06 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id c126-v6so7418295ywd.8 for ; Wed, 31 Oct 2018 21:43:06 -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 :mime-version:content-transfer-encoding; bh=IaITwuraDukMsGYidJDZeTXcBKjaBIgY+bVx6EB0wxo=; b=JJsE0ogegvWysA6hK14L3HTsf9nYoXrlRwatri14CtnhzsElIswoHla99asaMGiETM 1M25VzMD2kjK7XhkL/qpD+xkb0KaH5Cpw821r3lgRWnP5YUgKtebviIA5LDkNK9lHzth R64RTId1YzsOtow2DOBswcs8ufTQo5nqFunB8= 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=IaITwuraDukMsGYidJDZeTXcBKjaBIgY+bVx6EB0wxo=; b=NDCnl2cOrakkNZ0OlxV/OEOTMGj43hSKaA9xZQoczGQMrTx6J9Lx2EQtRBiYK3QTA/ zBoQSbehAoICG6ZxeZEueouFlRsXQ55yjMRkVjDEFG6ZXrfRjbZGoEhHj/NKi7s6G2lY KcGHxsVPQsh1aACFUoRju+z0IRNoYiHndrLH3/dyhPzM68gyTWSkYfwijYDBemcycyqh aIUy5W5uD5JA4iH4OFiqktKTblVKG1JpVaIOAJrqAPxSd5gXuFTKeb/gkl4o5m0swlB3 v9hNf5GCjU823aSXGYifk/d2Q2AZG/Z0hBg0a828FdthvRWMjNUIFI4dJ945ZRv6f6H/ VjTQ== X-Gm-Message-State: AGRZ1gLLRko3pt2MVLixJbB6bxY5F6ApoODi0GZfGxtc0CiFQX5Rjiw3 y6ADjiMuDKSo35qeoUID1H6ngfNDcLU= X-Received: by 2002:a81:c88:: with SMTP id 130-v6mr6022688ywm.491.1541047385069; Wed, 31 Oct 2018 21:43:05 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id k185-v6sm5578463ywc.98.2018.10.31.21.43.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 21:43:04 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Thu, 1 Nov 2018 13:45:17 +0900 Message-Id: <20181101044522.19899-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181101044039.19755-1-takahiro.akashi@linaro.org> References: <20181101044039.19755-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 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 Reviewed-by: Heinrich Schuchardt --- include/charset.h | 18 ++++++++++++++++++ lib/charset.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/charset.h b/include/charset.h index 4d45e246e515..5807f02b1a04 100644 --- a/include/charset.h +++ b/include/charset.h @@ -191,6 +191,24 @@ size_t u16_strlen(const u16 *in); */ size_t u16_strnlen(const u16 *in, size_t count); +/* TODO: add descriptions */ +/** + * u16_strcpy() - copy u16 string + * + * @dest: destination buffer + * @src: source buffer (null terminated) + * Return: 'dest' address + */ +u16 *u16_strcpy(u16 *dest, const u16 *src); + +/** + * u16_strdup() - duplicate u16 string + * + * @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) {