[PATCH] Modify strnstr.c.

Corinna Vinschen vinschen@redhat.com
Mon Aug 28 08:57:00 GMT 2017


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?


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20170828/d1e5abd3/attachment.sig>


More information about the Newlib mailing list