From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB688C433F5 for ; Wed, 27 Oct 2021 12:13:19 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C87860F70 for ; Wed, 27 Oct 2021 12:13:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C87860F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF52E8357C; Wed, 27 Oct 2021 14:13:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="ue0dEooF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3519583582; Wed, 27 Oct 2021 14:13:15 +0200 (CEST) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 365C18357B for ; Wed, 27 Oct 2021 14:13:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6E0763F17C for ; Wed, 27 Oct 2021 12:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1635336789; bh=/lgM6MLxWPOzl1jSsuIeyaLNq6XZCgARiZ7NGnqilSo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ue0dEooFDL5qlLVQ/fiUKrHlmLZZJnhTMz5RKODL6evnraypz3KxF3Sj6TETFjplD NOb8+83NOniy5IUmSoXrDsaSiittuxQZkixhlyRxW6zLnZXtZeVxuCiz8iNA6GwAxB 1xVT/IZs2y1irWWPxZ0eMdFtZpj2gpDOhSNhb2F8hzgF91FloRg3HebpEtkzd2j4ON R0wzh6ZN+bZPZXIhllr5voWbWU/dr+a4JWgh0Q9g9F5efF5oHXg4uYikJvBfECbnol 6dP41oS8uWlPkKdeBXfJblD5XYXtS4b5Fvb4SA1oU7SlQHewlwz6fg+GjuxNubs6/B Fa5HnsMx3HB/g== Received: by mail-wm1-f69.google.com with SMTP id p18-20020a05600c205200b0032ccb9d9f76so1095321wmg.8 for ; Wed, 27 Oct 2021 05:13:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=/lgM6MLxWPOzl1jSsuIeyaLNq6XZCgARiZ7NGnqilSo=; b=TY2TOAwFN7GmxLOy1Sm7sHKVazLu38UDVCSiJSp1uDz6LkjBWRcZhZE9OWU5JWFHtO ay6WShbs0cvoE8B3DyT10WN/qZEAoAQv+9mAvZtpSnYLwkKkq29Dmg+/EvTB9cVJoRKn 2+ZEHQ/l4nWKpaaCOWzKyu1NoxMreUzdiSnoD0iqo9n85FsNXd+NvUyDkbuVoEevOYxX bERMbwBqeNbJC6XrUCqiQyQF/u1HqD3lH+UQMg3cI20NPw7mTLWYTXl0OBCn+EPPlHhF GxB2iapWqILKUQ7ykQA2P5GfFz7UAQZcLp3FyGt+SH3yfgqNc/iG/cW9KcypLH+YGicR ozmw== X-Gm-Message-State: AOAM533H+BWVV7fGZcE9QyeY5sM8FGTCUUgqtPUZIn1m01WQtiz3Ml8O gC27fYEPHKnaPaTLz71OL9c7WtDYvPmikS+nGk0Op/mSZCViNXtTOC4ziaUv1Ce0uUMFKFK/Sce oTVf8rGTJ4qZhMFFiHraxluy/IlKByXg= X-Received: by 2002:a7b:c30c:: with SMTP id k12mr5451942wmj.38.1635336789045; Wed, 27 Oct 2021 05:13:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW3YndGoPt6/Rl5tFEkgI3d+u18OsjUkiy573L+yvTOFFM+n6m4EWLETeVsVDukMG9CE8jWg== X-Received: by 2002:a7b:c30c:: with SMTP id k12mr5451915wmj.38.1635336788821; Wed, 27 Oct 2021 05:13:08 -0700 (PDT) Received: from [192.168.123.35] (ip-88-152-144-157.hsi03.unitymediagroup.de. [88.152.144.157]) by smtp.gmail.com with ESMTPSA id g77sm3670417wmg.31.2021.10.27.05.13.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 05:13:08 -0700 (PDT) Message-ID: <684eb71b-9242-ddb9-4f95-50c86eb27a33@canonical.com> Date: Wed, 27 Oct 2021 14:13:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH v2 01/41] lib: Add a way to find the postiion of a trailing number Content-Language: en-US To: Simon Glass Cc: Michal Simek , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?Q?Marek_Beh=c3=ban?= , Lukas Auer , Dennis Gilmore , Heinrich Schuchardt , U-Boot Mailing List References: <20211023232635.9195-1-sjg@chromium.org> <20211023232635.9195-2-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20211023232635.9195-2-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On 10/24/21 01:25, Simon Glass wrote: > At present it is not possible to find out which part of the string is the > number part and which is before it. Add a new variant which provides this > feature, so we can separate the two in the caller. > > Signed-off-by: Simon Glass > --- > > (no changes since v1) > > include/vsprintf.h | 18 ++++++++++++++++++ > lib/strto.c | 14 ++++++++++++-- > 2 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/include/vsprintf.h b/include/vsprintf.h > index b4746301462..8230e7a5126 100644 > --- a/include/vsprintf.h > +++ b/include/vsprintf.h > @@ -118,6 +118,24 @@ long trailing_strtol(const char *str); > */ > long trailing_strtoln(const char *str, const char *end); > > +/** > + * trailing_strtoln() - extract a trailing integer from a fixed-length string > + * > + * Given a fixed-length string this finds a trailing number on the string > + * and returns it. For example, "abc123" would return 123. Only the > + * characters between @str and @end - 1 are examined. If @end is NULL, it is > + * set to str + strlen(str). Please, provide a test with as string like 'abc123def456'. > + * > + * @str: String to exxamine > + * @end: Pointer to end of string to examine, or NULL to use the > + * whole string > + * @lenp: If non-NULL, this is set to the number of characters before the > + * number starts, e.g. for "mmc0" this would be 3; if no trailing number is > + * found, it is set to the length of the whole string > + * @return training number if found, else -1 > + */ > +long trailing_strtoln_len(const char *str, const char *end, int *lenp); Usage in a caller would be easier if you would return a pointer to the first digit instead of a length. Best regards Heinrich > + > /** > * panic() - Print a message and reset/hang > * > diff --git a/lib/strto.c b/lib/strto.c > index 7bba1e3e549..13ae22a87a1 100644 > --- a/lib/strto.c > +++ b/lib/strto.c > @@ -183,7 +183,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base) > return simple_strtoull(cp, endp, base); > } > > -long trailing_strtoln(const char *str, const char *end) > +long trailing_strtoln_len(const char *str, const char *end, int *lenp) > { > const char *p; > > @@ -191,14 +191,24 @@ long trailing_strtoln(const char *str, const char *end) > end = str + strlen(str); > if (isdigit(end[-1])) { > for (p = end - 1; p > str; p--) { > - if (!isdigit(*p)) > + if (!isdigit(*p)) { > + if (lenp) > + *lenp = p - str + 1; > return dectoul(p + 1, NULL); > + } > } > } > + if (lenp) > + *lenp = end - str; > > return -1; > } > > +long trailing_strtoln(const char *str, const char *end) > +{ > + return trailing_strtoln_len(str, end, NULL); > +} > + > long trailing_strtol(const char *str) > { > return trailing_strtoln(str, NULL); >