From patchwork Tue May 13 14:58:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 30061 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D6E9520369 for ; Tue, 13 May 2014 15:09:17 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id ma3sf2123311pbc.11 for ; Tue, 13 May 2014 08:09:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=OuMwTBgua4Sn4UyYZ4TVka1yP7Dqo/mqOcKSUJ4PiMI=; b=Vt8ZKlKsiIe0c6VDv23FKnRSNVc0fFNWUBQUht+v0yx/EJZ+W05dFD2hD5d7fVSA7d EgC3s3hpLd7xzwnWyIz7l4ysZt7Z5MqH9ocfo8PvPUkrxqOjMDXOHVDxomlPL4qTNw+i +jEdbHfGTSYoFIASeOZYiOmjmqfor22XmwI8neMY9eaKuNo5YEdwgnlcyTI5ulVFg3r5 Mqps7gXwb/IGg00X2bQyojfUx+oZ2NI+rSeyBVN6P4ccga6h4ZbFBAf2L/pW2yfFYV1R 3lT0XRFvqBpBypNdMhjF4qvzfD2qhRtWTr77CepWYYN6soLHMzxdXj6Wz+gv09fPlCXE UoeA== X-Gm-Message-State: ALoCoQlAYWugfxJ8M8ACnCI/fT4Ju4Lk/7K6a6VREhrJDAN8IkA62bYIkYzm35N4BdSpW35e1+bp X-Received: by 10.66.65.109 with SMTP id w13mr14999340pas.21.1399993757035; Tue, 13 May 2014 08:09:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.141 with SMTP id r13ls1097704qgd.98.gmail; Tue, 13 May 2014 08:09:16 -0700 (PDT) X-Received: by 10.52.228.134 with SMTP id si6mr24593484vdc.5.1399993756878; Tue, 13 May 2014 08:09:16 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id tb2si2690531vdc.129.2014.05.13.08.09.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 08:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so631793vcb.30 for ; Tue, 13 May 2014 08:09:16 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr4462613vcb.18.1399993756700; Tue, 13 May 2014 08:09:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp158617vcb; Tue, 13 May 2014 08:09:16 -0700 (PDT) X-Received: by 10.68.213.97 with SMTP id nr1mr5865714pbc.52.1399993755973; Tue, 13 May 2014 08:09:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rw8si8140210pbc.147.2014.05.13.08.09.14; Tue, 13 May 2014 08:09:15 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965162AbaEMPJE (ORCPT + 27 others); Tue, 13 May 2014 11:09:04 -0400 Received: from mail-ee0-f52.google.com ([74.125.83.52]:35633 "EHLO mail-ee0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934081AbaEMO6n (ORCPT ); Tue, 13 May 2014 10:58:43 -0400 Received: by mail-ee0-f52.google.com with SMTP id e53so512076eek.39 for ; Tue, 13 May 2014 07:58:42 -0700 (PDT) X-Received: by 10.14.98.131 with SMTP id v3mr4522249eef.77.1399993122755; Tue, 13 May 2014 07:58:42 -0700 (PDT) Received: from trevor.secretlab.ca (host109-150-134-147.range109-150.btcentralplus.com. [109.150.134.147]) by mx.google.com with ESMTPSA id a6sm40754868eem.16.2014.05.13.07.58.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 07:58:41 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id AB7F3C409DE; Tue, 13 May 2014 15:58:38 +0100 (BST) From: Grant Likely To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Grant Likely Subject: [PATCH 1/3] lib: add glibc style strchrnul() variant Date: Tue, 13 May 2014 15:58:33 +0100 Message-Id: <1399993115-21552-2-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399993115-21552-1-git-send-email-grant.likely@linaro.org> References: <1399993115-21552-1-git-send-email-grant.likely@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The strchrnul() variant helpfully returns a the end of the string instead of a NULL if the requested character is not found. This can simplify string parsing code since it doesn't need to expicitly check for a NULL return. If a valid string pointer is passed in, then a valid null terminated string will always come back out. Signed-off-by: Grant Likely --- include/linux/string.h | 3 +++ lib/string.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index ac889c5ea11b..d36977e029af 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -52,6 +52,9 @@ extern int strncasecmp(const char *s1, const char *s2, size_t n); #ifndef __HAVE_ARCH_STRCHR extern char * strchr(const char *,int); #endif +#ifndef __HAVE_ARCH_STRCHRNUL +extern char * strchrnul(const char *,int); +#endif #ifndef __HAVE_ARCH_STRNCHR extern char * strnchr(const char *, size_t, int); #endif diff --git a/lib/string.c b/lib/string.c index 9b1f9062a202..059636f92c26 100644 --- a/lib/string.c +++ b/lib/string.c @@ -301,6 +301,21 @@ char *strchr(const char *s, int c) EXPORT_SYMBOL(strchr); #endif +#ifndef __HAVE_ARCH_STRCHRNUL +/** + * strchr - Find the first occurrence of a character in a string + * @s: The string to be searched + * @c: The character to search for + */ +char *strchrnul(const char *s, int c) +{ + while (*s && *s != (char)c) + s++; + return (char *)s; +} +EXPORT_SYMBOL(strchrnul); +#endif + #ifndef __HAVE_ARCH_STRRCHR /** * strrchr - Find the last occurrence of a character in a string