From patchwork Fri Mar 14 17:11:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 26274 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EFA0B20143 for ; Fri, 14 Mar 2014 17:12:46 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id g12sf10698079oah.11 for ; Fri, 14 Mar 2014 10:12:46 -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=vW/hkWONM6UVYK0AEKfBa90DRWmHXTgMA4KbYLow/XQ=; b=ISmaAhnnLE20jI3Oukb9bbh1JdIqQPTNTmZSw1DS3vOpWIp670YuGUq6OZiw7SU+Cx +NB68cXv3q+4lEBOy1kd0srrvibcbgiitlXnV09nPD47yjt5AEzk0erDzDUJlNYn3w5q 69tfI6hPhNcTC26T8cIVwyC13PB5JikAuSD2yo4uByeNeQFE++i7Z+nRsIZQ56CIzDVF WWRSbdgvbjpVHaauzaJ84qQqT2lpojOetRtFLC+gSBMKIVf+La4BdOVQe2ggppc5e1I8 V4kLAROsMKe+/Ps2tsNXBrg2+p+AuyaF/hNDMNN/7HK5NbY9nipVGHzdHwdQtrnLq6eE ju3w== X-Gm-Message-State: ALoCoQl2i/aAvjaQao3lyZ2mWafEsTHPUakF/a3RuyP/5rdfMUQrDv8UI5CzcMg/nKKDR0lWWYU6 X-Received: by 10.183.3.36 with SMTP id bt4mr3641058obd.29.1394817166522; Fri, 14 Mar 2014 10:12:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.133 with SMTP id b5ls808787qge.38.gmail; Fri, 14 Mar 2014 10:12:46 -0700 (PDT) X-Received: by 10.52.3.129 with SMTP id c1mr967850vdc.37.1394817166406; Fri, 14 Mar 2014 10:12:46 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id sv2si2327361vdc.55.2014.03.14.10.12.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 10:12:46 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id if17so3005622vcb.8 for ; Fri, 14 Mar 2014 10:12:46 -0700 (PDT) X-Received: by 10.220.103.141 with SMTP id k13mr1915049vco.25.1394817166306; Fri, 14 Mar 2014 10:12:46 -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.78.9 with SMTP id i9csp35794vck; Fri, 14 Mar 2014 10:12:45 -0700 (PDT) X-Received: by 10.66.142.132 with SMTP id rw4mr10543496pab.6.1394817165437; Fri, 14 Mar 2014 10:12:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si6341243pba.1.2014.03.14.10.12.44; Fri, 14 Mar 2014 10:12:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756228AbaCNRMg (ORCPT + 26 others); Fri, 14 Mar 2014 13:12:36 -0400 Received: from mail-ee0-f52.google.com ([74.125.83.52]:50572 "EHLO mail-ee0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756087AbaCNRMB (ORCPT ); Fri, 14 Mar 2014 13:12:01 -0400 Received: by mail-ee0-f52.google.com with SMTP id e49so1623404eek.39 for ; Fri, 14 Mar 2014 10:11:59 -0700 (PDT) X-Received: by 10.14.246.196 with SMTP id q44mr9345460eer.45.1394817119865; Fri, 14 Mar 2014 10:11:59 -0700 (PDT) Received: from trevor.secretlab.ca (host109-153-30-112.range109-153.btcentralplus.com. [109.153.30.112]) by mx.google.com with ESMTPSA id x3sm18358634eep.17.2014.03.14.10.11.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 10:11:59 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 08205C40A1B; Fri, 14 Mar 2014 17:11:56 +0000 (GMT) From: Grant Likely To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Pantelis Antoniou , Grant Likely Subject: [RFC v3 2/3] lib: add glibc style strchrnul() variant Date: Fri, 14 Mar 2014 17:11:48 +0000 Message-Id: <1394817109-26199-3-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1394817109-26199-1-git-send-email-grant.likely@linaro.org> References: <1394817109-26199-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=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 e5878de4f101..879e839cc555 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