From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18776 invoked by alias); 28 Aug 2017 10:50:40 -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 18761 invoked by uid 89); 28 Aug 2017 10:50:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=Including, H*F:D*qq.com, H*Ad:D*qq.com X-HELO: smtpbg299.qq.com Received: from smtpbg299.qq.com (HELO smtpbg299.qq.com) (184.105.67.99) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Aug 2017 10:50:36 +0000 X-QQ-mid: esmtp20t1503917431ts438u4ok Received: from [192.168.1.102] (unknown [114.212.116.37]) by esmtp4.qq.com (ESMTP) with SMTP id 0 for ; Mon, 28 Aug 2017 18:50:30 +0800 (CST) X-QQ-SSF: 01000000000000505H101F00000000W X-QQ-FEAT: 9NFkmNiL4hcLQREqtm4kP8g6H6zzAJE0NBRniGEnskrHAf47zpA1pzUQG4dIL GZTJatrhDcw+NA0LqJ3dC8TSf2cbRYd9WqV687lScYBul1hKSuSy9S8DgQ0/MkSnfzFztcU rk2azZm83zdGjmb0sMsFWuBx7FkwGj/Ty4/pPXkPL+ZCySWI/i88NY/UcYhdcPEWeUq46pq wWbU8lCRiXSXdlZeLJuEHE6mmmFVX+XrhtRcAkb4lkcWqekjNGeYaHzEiNTNA/FMqbLgeoY 6RjuXZgnFj/2qi X-QQ-GoodBg: 0 Subject: Re: [PATCH] Modify strnstr.c. To: newlib@sourceware.org References: <1503754090-28619-1-git-send-email-1473996754@qq.com> <20170828084522.GD18275@calimero.vinschen.de> From: Sichen Zhao <1473996754@qq.com> Message-ID: <48efb3a4-e8df-506f-7e0d-1ca4d5d9ea5f@qq.com> Date: Mon, 28 Aug 2017 13:38:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170828084522.GD18275@calimero.vinschen.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-QQ-SENDSIZE: 520 X-QQ-FName: 25CC33967C7A42FDB8CEDA8A86594EC2 X-QQ-LocalIP: 10.208.130.95 X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00901.txt.bz2 > On Aug 26 21:28, Sichen Zhao wrote: >> --- >> newlib/libc/string/strnstr.c | 24 ++++++++---------------- >> 1 file changed, 8 insertions(+), 16 deletions(-) >> >> diff --git a/newlib/libc/string/strnstr.c b/newlib/libc/string/strnstr.c >> index da5e5bd..7c87bbd 100644 >> --- a/newlib/libc/string/strnstr.c >> +++ b/newlib/libc/string/strnstr.c >> @@ -44,22 +44,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; >> } >> -- >> 2.7.4 > Input needed: > > Given this is a complete reimplementation not based on FreeBSD code at > all, and given the code has been contributed by Eric, shouldn't we > remove the entire copyright header and move this under newlib default > licensing? Including remove the "__FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 251069 2013-05-28 20:57:40Z emaste $");", right? > > Thanks, > Corinna >