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 4A20EC433F5 for ; Sat, 23 Oct 2021 23:27:23 +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 8D07F60E9C for ; Sat, 23 Oct 2021 23:27:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8D07F60E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 0B0B683552; Sun, 24 Oct 2021 01:27:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gghA4T7s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6545C8348B; Sun, 24 Oct 2021 01:26:53 +0200 (CEST) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3483B8327C for ; Sun, 24 Oct 2021 01:26:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x329.google.com with SMTP id l10-20020a056830154a00b00552b74d629aso9318351otp.5 for ; Sat, 23 Oct 2021 16:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Z6kGGv9BdX+cH63ojsEK4i8Prt5Wi2VbUx+D7Gi4F0=; b=gghA4T7s6NHlfvT9vgY/C5boorZp89GEnbFyW+sfGa7B9pJezPdxdOkKmNOp/GZvNm 53OhG9snv4yuHXy8xedUcOq6mLIrAqSq3ePSnq/1DPrpaxGXE3nNXkZ60L7kw03SVotd m5zKoS8JwpNs9osgpJuAx1bdugzxT9cdzSrZ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Z6kGGv9BdX+cH63ojsEK4i8Prt5Wi2VbUx+D7Gi4F0=; b=sq3qAjGHnDeT7LckcrSs1HOjDQFdYThD2WTHn8bBiu4P/Fz6y9myWxJpLJpVvnA8ay jnqos4+ZtMQTRC1K/uQhAsCpHTZuEnpjYBIRIP+gjGZkBBv3qztwguZjp3m/4XuM47nG kVKPD2m5ywOIS4jFP0W6rSAj/nIES2dK3c0SxOs/LTi4HpiMimbzD1kUd0yHBcgFLY+9 IqySftzOCO7/ZkQI4nrARfno7lE15jwV9sPHnLf+eQPJDMxyPfEQ5iBMYa4veuKblZdD plVsSvMiW7nvSKyV/OnASxwdheYJGAkOZahGVqg81G0Hcc3+tlJdXUjmmhIMFPearbzD d2+A== X-Gm-Message-State: AOAM532S5FPHrb2iq2iaPqzWhR+RlFDrFkMgQeuXrSx3O1YNTjgk3GFu mK1PHBIO6/oxUPvZCSOXSxOPqQwtyA9sFg== X-Google-Smtp-Source: ABdhPJy/vXgbfHrXmVbx7B6ovhJnGloXb6ztjkgSRJ0mIgDusbaY5auFMzvF2r2twjPDh2IHGa972w== X-Received: by 2002:a05:6830:124d:: with SMTP id s13mr7065789otp.336.1635031604576; Sat, 23 Oct 2021 16:26:44 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:26:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass Subject: [PATCH v2 01/41] lib: Add a way to find the postiion of a trailing number Date: Sat, 23 Oct 2021 17:25:55 -0600 Message-Id: <20211023232635.9195-2-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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). + * + * @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); + /** * 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); -- 2.33.0.1079.g6e70778dc9-goog