From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63849 invoked by alias); 10 Sep 2017 04:04:01 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 63419 invoked by uid 89); 10 Sep 2017 04:04:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=WAY, SERVICES, california, DIRECT X-HELO: smtp-out-so.shaw.ca Received: from smtp-out-so.shaw.ca (HELO smtp-out-so.shaw.ca) (64.59.136.139) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 04:03:58 +0000 Received: from [192.168.1.100] ([24.64.240.204]) by shaw.ca with SMTP id qtTPdlqdWDJTWqtTQdinnV; Sat, 09 Sep 2017 22:03:56 -0600 X-Authority-Analysis: v=2.2 cv=B4DJ6KlM c=1 sm=1 tr=0 a=MVEHjbUiAHxQW0jfcDq5EA==:117 a=MVEHjbUiAHxQW0jfcDq5EA==:17 a=IkcTkHD0fZMA:10 a=x7bEGLp0ZPQA:10 a=6I5d2MoRAAAA:8 a=GwRmOh8_7XF0HXO3-xcA:9 a=QEXdDO2ut3YA:10 a=IjZwj45LgO3ly-622nXo:22 Reply-To: Brian.Inglis@Shaw.ca Subject: Re: [PATCH v2] Modify strnstr.c. To: newlib@sourceware.org References: <1504062237-19638-1-git-send-email-1473996754@qq.com> From: Brian Inglis Message-ID: Date: Sun, 10 Sep 2017 04:04:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1504062237-19638-1-git-send-email-1473996754@qq.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfHV2832pwCiDpm9yBO8IF7GnZisTqqOnqbQ0us7e5wD3CoaCZeJCXhGJz4wE1R8knP2BUZPKuAad/mQY3IIsUvqlKNcAAbTzEVfegSlYd790E7g2A/29 TnEc+D3lnBfsY976S22HkfQupWh/W71AtflcHm82n88WgeLJsZQ16/FMXtKUKQGoeFFrJ1y50sDu7w== X-SW-Source: 2017/txt/msg00966.txt.bz2 On 2017-08-29 21:03, Sichen Zhao wrote: > --- > newlib/libc/string/strnstr.c | 65 +++++++------------------------------------- > 1 file changed, 10 insertions(+), 55 deletions(-) > > diff --git a/newlib/libc/string/strnstr.c b/newlib/libc/string/strnstr.c > index da5e5bd..05d86ee 100644 > --- a/newlib/libc/string/strnstr.c > +++ b/newlib/libc/string/strnstr.c > @@ -1,42 +1,5 @@ > -/*- > - * Copyright (c) 2001 Mike Barcroft > - * Copyright (c) 1990, 1993 > - * The Regents of the University of California. All rights reserved. > - * > - * This code is derived from software contributed to Berkeley by > - * Chris Torek. > - * > - * Redistribution and use in source and binary forms, with or without > - * modification, are permitted provided that the following conditions > - * are met: > - * 1. Redistributions of source code must retain the above copyright > - * notice, this list of conditions and the following disclaimer. > - * 2. Redistributions in binary form must reproduce the above copyright > - * notice, this list of conditions and the following disclaimer in the > - * documentation and/or other materials provided with the distribution. > - * 3. Neither the name of the University nor the names of its contributors > - * may be used to endorse or promote products derived from this software > - * without specific prior written permission. > - * > - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND > - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE > - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > - * SUCH DAMAGE. > - */ > - > -#if defined(LIBC_SCCS) && !defined(lint) > -static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; > -#endif /* LIBC_SCCS and not lint */ > -#include > -__FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 251069 2013-05-28 20:57:40Z emaste $"); > - > +#undef __STRICT_ANSI__ > +#include <_ansi.h> > #include > > /* > @@ -44,22 +7,14 @@ __FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 251069 2013-05-28 20:57:40Z e > * first slen characters of s. > */ > char * > -strnstr(const char *s, const char *find, size_t slen) > +strnstr(const char *haystack, const char *needle, size_t haystack_len) > { > - char c, sc; > - size_t len; > + size_t needle_len = strnlen(needle, haystack_len); > > - if ((c = *find++) != '\0') { > - len = strlen(find); > - do { > - do { > - if (slen-- < 1 || (sc = *s++) == '\0') > - return (NULL); > - } while (sc != c); > - if (len > slen) > - return (NULL); > - } while (strncmp(s, find, len) != 0); > - s--; > - } > - return ((char *)s); > + if (needle_len < haystack_len || !needle[needle_len]) { > + char *x = memmem(haystack, haystack_len, needle, needle_len); > + if (x && !memchr(haystack, 0, x - haystack)) > + return x; > + } > + return NULL; > } Getting memmem undefined building Cygwin from git latest. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada