From patchwork Fri Dec 14 10:10:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 153797 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1875303ljp; Fri, 14 Dec 2018 02:08:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/XW1xdbKekPlajdp1NQWyVibpm6qa8PZJxyJxox76wg/ZdBmvwAzAtV5L/qtYok1aAx5MXt X-Received: by 2002:a50:90c6:: with SMTP id d6mr2576046eda.15.1544782094702; Fri, 14 Dec 2018 02:08:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544782094; cv=none; d=google.com; s=arc-20160816; b=JsOOVV7zw5i8BYlcBs7KIeuqIBk8RZNHKoK/85Dky6S3/hs6jvAtMBFNZGVZSMPjh4 0fuMkw4Fa6K8DSwH+ONDlW4DQODpfEy/5Jcw/w2h5QauzE8udvPBpbRc4olphvDF03Hb 154p9NJB0YLnsSJ2qrx+SztK1fPwj69FxMsEPCccg+XBdEeCQh9CljbQm5Z+xnuvcOud gVLStrMDnTnmPcpPsAxdGDqC7y3VrAS4EbYsaZhc+iFPvJEgC9UQtxLCuoe7DzNKCjHB acWh3nTXhgXJ9kbMQATxd/0nDRFwH/+zXEzH9T7tVOePm6PcAZoa+4XINEYU+0mwSTCS 2rGg== 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=GUccqqYhwg15TELvZH3JTe4sk7dndKMGR69i9tyUAWc=; b=AvYKwwD67/6cgLnBRPuvTazJPRbZVGTlLffv8hWnuDwFqo02sSSW7xIHe3KjrdKqZ9 aDtdK2UJc3gPDdUvQjfmnlgOPx3eU2HiFR2Nuasw0RFL91y1JXBk2Wn8w8ej1SA3aIEh ukatpCvkWAimGuRyWidnKW3HjgCjPM3+NVxVu4eLM+n3fZU3qO1v0PviDYGRQxSRl82M V76dJgcEZzi+YnQOyaqdOWFjUhx4omPixMdX9M7ggau3if7Rl0Z2JrbqHYsCWyBjO98e jmounF1+wpmxaEURDfG29Ong2cyoCnW+qMYvA3Li9BxmmdubYZj/BJp6ECBpHlajvSkj NarQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UKAMYScP; 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 v22-v6si1573634ejb.264.2018.12.14.02.08.14; Fri, 14 Dec 2018 02:08:14 -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=UKAMYScP; 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 36309C22677; Fri, 14 Dec 2018 10:07:48 +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 49B6BC220F3; Fri, 14 Dec 2018 10:07:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A4A4EC2235B; Fri, 14 Dec 2018 10:07:34 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 07C97C226A2 for ; Fri, 14 Dec 2018 10:07:31 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id d2so2026043ybs.11 for ; Fri, 14 Dec 2018 02:07:30 -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=GDbwyOlbLZoLuHwKkVV3jb0+MDyBabUVV/cVAnco7O4=; b=UKAMYScPA6ZE6pX5gMw5b60fJ3CmEYDk4+/b4TIHI8cIc1RDNCUQIGjS7Jx5nJ+1av XEjq2jqA+4WzUmGjqq3JRwlJ4eJJ3bEzmWGVfgFzDknuMXz0pg/i1jbvo1UHBfCzE2Cf lzwE19L/TEsyUkEy3bighBUXLOzXzdu+s5rys= 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=GDbwyOlbLZoLuHwKkVV3jb0+MDyBabUVV/cVAnco7O4=; b=Ks/fHznYVy6jWoFA4TQyohDt2SAVBRyu+Q2r/Ijag9rP+D49UjVzmBt4la8xe60vwF qZ1uEfo6ISs/oQwpWqBejnt6X/xEPF5cBOip4IxnCcHAsiSx5G2S9Vrgg7zqzNhGaiP8 3jkKdb8HegwGRs1f9jXjbVlYopI6HgbcaY6Ud9w2LHDG+lX28e3/y/R9chW3SP33gqki ZhFQ9fa36vJxdQRxUnGrMjvFRE8vQmgKNRjrg1nzrKSlvXl0NjQOyBuuWbK+edBxq9Ys CE/GjvQnUa8zmpcuBPbfdfqHF+GFIsL2VROZI9vI+gnZWyQOtmrhKg/JedBFfaJaniP+ OrOg== X-Gm-Message-State: AA+aEWaPJpVHtwoDEf58b0psCEqDQ5tb5xtArjjwxlJJOAFJRGukDjA4 fb9RT8djlNF09sYsyhzoeAJdOg== X-Received: by 2002:a25:3d47:: with SMTP id k68mr2358633yba.4.1544782049936; Fri, 14 Dec 2018 02:07:29 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y1sm1307165ywe.86.2018.12.14.02.07.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 02:07:29 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 14 Dec 2018 19:10:38 +0900 Message-Id: <20181214101043.14067-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181214101043.14067-1-takahiro.akashi@linaro.org> References: <20181214101043.14067-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RESEND 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 Reviewed-by: Heinrich Schuchardt --- 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) {