From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754028AbbGAJoC (ORCPT ); Wed, 1 Jul 2015 05:44:02 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:35655 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752220AbbGAJmg (ORCPT ); Wed, 1 Jul 2015 05:42:36 -0400 From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Cc: Mark Brown , linux-acpi@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, "Rafael J. Wysocki" , alsa-devel@alsa-project.org, Tomeu Vizoso Subject: [PATCH v2 03/12] string: Introduce strends() Date: Wed, 1 Jul 2015 11:40:58 +0200 Message-Id: <1435743667-11987-4-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> References: <1435743667-11987-1-git-send-email-tomeu.vizoso@collabora.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To avoid duplicating code in upcoming patches that will check for postfixes in strings, add strends(). Signed-off-by: Tomeu Vizoso --- Changes in v2: - Move strends to string.h include/linux/string.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index d5dfe3e..4244363 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -146,6 +146,19 @@ static inline bool strstarts(const char *str, const char *prefix) return strncmp(str, prefix, strlen(prefix)) == 0; } +/** + * strends - does @str end with @postfix? + * @str: string to examine + * @postfix: postfix to look for + */ +static inline bool strends(const char *str, const char *postfix) +{ + if (strlen(str) < strlen(postfix)) + return false; + + return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; +} + size_t memweight(const void *ptr, size_t bytes); void memzero_explicit(void *s, size_t count); -- 2.4.1