Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5732150rwr; Mon, 1 May 2023 09:57:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41K+flcN6QF4Op8BMFOIqRc1XafXnEJgTEslWYa3cd9cPtBgMoWa+Eqq4noBUKQ4bTQ9lZ X-Received: by 2002:a05:6a00:1905:b0:63d:408a:e14 with SMTP id y5-20020a056a00190500b0063d408a0e14mr21562862pfi.4.1682960231516; Mon, 01 May 2023 09:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682960231; cv=none; d=google.com; s=arc-20160816; b=W/5aS8aErzUmPDfdVC2ba9DLfp7V03nQPDGYISdIxQNP6jmT0k03TAYQgpuwg6o/5d OjxOCFqLE//aEZKiBAzuFU1FbroNFaBSZIoN2TP+ebai0WCPvXUTa9Mu9IgwPOIxAh6f Msq8/EvB67q9hlpXh24js8vCPW4PQbrIOXoVzmju+MApKQCSy/7rtxaZmAIZhRKv/dPK j7cWqznVGQ834W96WizxBRPYOJY8OEOJFZL+uQi0IUzwOzLkY1u7y67GnSDw453gakO4 5h43sSd2MCpA6r3CNW23ld8jRcgnMWqiuVFq+xn5hFiVwgqf2DLnRtEaw9oqFkD3OsUc 3Oyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=AsvePdIIpK1hSWiMR4JNg9vJpL7RbQEpCCaVPwkxl+U=; b=zfqLbVE9RyDefo3spls4V6lxnwyIVG5ypA2Q6dljkWkbddF+MmcJZtz1TQn7NYJMjm nSMBswiBf7deJEY5oVuELfnzOwjCR+GG4DAbcfEoSOdlOXyrG6SgPTBonSQtaE/AFaSP WxnN0HmzSbJPY9+gzb5oFBYc0DH2aN1+J9RE/OrHd5VhTd7aFoOJnCizb708A36Dr1eC 2TwAEdUsU2Fp+uAJyrCAsT2Qm2ES6LEX8UZCku+jsAtpzoZijzqZ/SCxvgcPqgLvGfMb of9+cYbKeRhtqdWIHeXfTtYHdCekKtcTAJWfYae5q6fJbY0mvDye88DYxFGU3h8WBVJo Cu4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=FUEHKTcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a621d07000000b0063b60063f55si28691296pfd.382.2023.05.01.09.56.58; Mon, 01 May 2023 09:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=FUEHKTcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232808AbjEAQ4c (ORCPT + 99 others); Mon, 1 May 2023 12:56:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232402AbjEAQ4F (ORCPT ); Mon, 1 May 2023 12:56:05 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0326F1FCE for ; Mon, 1 May 2023 09:55:22 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-559fb850e08so31595667b3.3 for ; Mon, 01 May 2023 09:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682960122; x=1685552122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AsvePdIIpK1hSWiMR4JNg9vJpL7RbQEpCCaVPwkxl+U=; b=FUEHKTcj/6Oaa/jf/hG74LwWnPzMzDXETDPC/OZPn9YmdSr3Je1dLjqI5qQFH1sW3q Bq/alOSo7JqKEqD9rgKcyUF43rVJZUIyQmx1G3PllnLeg5Yg39a7Bnek6w/Qmd8uXbJK EsGaYT+egztrqXkT7lGAkap+Gl5GwKP4LRCOjo5ZnVALaZHiuOt5sB/2YrOa8QMVBMrC FKm9pwPXa7lut/5XYzJLVlhPqGzsdKvhEJFlIIbig8wN8WeEjVJtPWgEipfIbTn79FXC wbTQc/DXAGa8hfnAWPDItUw4SLFFckirBkUuGFld0u0/pGt++nX/qQJEblW72Hij4gvi rVdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682960122; x=1685552122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AsvePdIIpK1hSWiMR4JNg9vJpL7RbQEpCCaVPwkxl+U=; b=IDUiKtbgk6zVW5XYjUaYko16beZInx3QuT8rf9WtmErHdvX/GjXt/xGX4oOdu0YfKl t5QX/eEV8n52IVGuEJFx2pC+Qb1tAQ7FvyEAxVMzYmutQZTCnBvZOadBIIkW+kbxUIwB QnRHUmwZ+8cexD94EINu9jd9JOQ3OZk76q0DK5BEHW1mBAnQNyBd5As1bXPmtfM5pfvZ 1EvzzrOkNfd0SZIatHubIuTeJFyowgEHPfIY5PuilCxmBQTAnsYU6IxEiWDs+5J+C0ec xILlK9EF+QciwrX0JBe8aNLulrq8Bmg6J5QqZzfySUA35M5Gl3YezEyo5dIP1TjZykrR f00g== X-Gm-Message-State: AC+VfDw5UNzbjBdl1R1wywvScsGUPzs8Hq1o3qkcuPxShuCJCo/2rH8I gGUxIyZBcuBca/UtA7zpqKR3HOdM+Yk= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6d24:3efd:facc:7ac4]) (user=surenb job=sendgmr) by 2002:a81:7653:0:b0:54f:a60c:12eb with SMTP id j19-20020a817653000000b0054fa60c12ebmr8139444ywk.1.1682960121808; Mon, 01 May 2023 09:55:21 -0700 (PDT) Date: Mon, 1 May 2023 09:54:16 -0700 In-Reply-To: <20230501165450.15352-1-surenb@google.com> Mime-Version: 1.0 References: <20230501165450.15352-1-surenb@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230501165450.15352-7-surenb@google.com> Subject: [PATCH 06/40] lib/string.c: strsep_no_empty() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet This adds a new helper which is like strsep, except that it skips empty tokens. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan --- include/linux/string.h | 1 + lib/string.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index c062c581a98b..6cd5451c262c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -96,6 +96,7 @@ extern char * strpbrk(const char *,const char *); #ifndef __HAVE_ARCH_STRSEP extern char * strsep(char **,const char *); #endif +extern char *strsep_no_empty(char **, const char *); #ifndef __HAVE_ARCH_STRSPN extern __kernel_size_t strspn(const char *,const char *); #endif diff --git a/lib/string.c b/lib/string.c index 3d55ef890106..dd4914baf45a 100644 --- a/lib/string.c +++ b/lib/string.c @@ -520,6 +520,25 @@ char *strsep(char **s, const char *ct) EXPORT_SYMBOL(strsep); #endif +/** + * strsep_no_empt - Split a string into tokens, but don't return empty tokens + * @s: The string to be searched + * @ct: The characters to search for + * + * strsep() updates @s to point after the token, ready for the next call. + */ +char *strsep_no_empty(char **s, const char *ct) +{ + char *ret; + + do { + ret = strsep(s, ct); + } while (ret && !*ret); + + return ret; +} +EXPORT_SYMBOL_GPL(strsep_no_empty); + #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value -- 2.40.1.495.gc816e09b53d-goog