From patchwork Thu May 17 17:40:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 915623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mzBH18M5z9s3c for ; Fri, 18 May 2018 03:41:27 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40mzBG5XRHzF27W for ; Fri, 18 May 2018 03:41:26 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40mz9r3ZMjzF27Q for ; Fri, 18 May 2018 03:41:04 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72625401EF09 for ; Thu, 17 May 2018 17:41:02 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFBC76F9E6 for ; Thu, 17 May 2018 17:41:01 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Thu, 17 May 2018 19:40:52 +0200 Message-Id: <1526578856-30967-6-git-send-email-thuth@redhat.com> In-Reply-To: <1526578856-30967-1-git-send-email-thuth@redhat.com> References: <1526578856-30967-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 17 May 2018 17:41:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 17 May 2018 17:41:02 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH 5/9] libc: Implement strrchr() X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This function will be used in one of the next patches to find the last slash in a file name string. Signed-off-by: Thomas Huth Reviewed-by: Greg Kurz --- lib/libc/string/Makefile.inc | 2 +- lib/libc/string/strrchr.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/libc/string/strrchr.c diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 7ccf3c4..0a77738 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -13,7 +13,7 @@ STRING_SRC_C = strcat.c strchr.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c strstr.c memset.c memcpy.c memmove.c memchr.c \ - memcmp.c strcasecmp.c strncasecmp.c strtok.c + memcmp.c strcasecmp.c strncasecmp.c strtok.c strrchr.c STRING_SRC_ASM = STRING_SRCS = $(STRING_SRC_C:%=$(STRINGCMNDIR)/%) $(STRING_SRC_ASM:%=$(STRINGCMNDIR)/%) STRING_OBJS = $(STRING_SRC_C:%.c=%.o) $(STRING_SRC_ASM:%.S=%.o) diff --git a/lib/libc/string/strrchr.c b/lib/libc/string/strrchr.c new file mode 100644 index 0000000..7824020 --- /dev/null +++ b/lib/libc/string/strrchr.c @@ -0,0 +1,28 @@ +/****************************************************************************** + * libc strrchr() implementation + * + * This program and the accompanying materials are made available under + * the terms of the BSD License which accompanies this distribution, and + * is available at http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * Thomas Huth - initial implementation + *****************************************************************************/ + +#include + +char * +strrchr(const char *s, int c) +{ + char cb = c; + char *ptr = (char *)s + strlen(s) - 1; + + while (ptr >= s) { + if (*ptr == cb) { + return ptr; + } + ptr -= 1; + } + + return NULL; +}