public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 2/2] Port strnstr.c to newlib.
  2017-08-25  7:53 [PATCH v3 1/2] Import strnstr.c from FreeBSD Sichen Zhao
@ 2017-08-25  7:36 ` Sichen Zhao
  2017-08-25 17:56 ` [PATCH v3 1/2] Import strnstr.c from FreeBSD Corinna Vinschen
  1 sibling, 0 replies; 8+ messages in thread
From: Sichen Zhao @ 2017-08-25  7:36 UTC (permalink / raw)
  To: newlib; +Cc: gedare, joel, christian.mauderer, sebastian.huber, Sichen Zhao

---
 newlib/libc/include/string.h   | 3 +++
 newlib/libc/string/Makefile.am | 1 +
 2 files changed, 4 insertions(+)

diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
index 7833aa1..9c536f3 100644
--- a/newlib/libc/include/string.h
+++ b/newlib/libc/include/string.h
@@ -121,6 +121,9 @@ size_t	 _EXFUN(strnlen,(const char *, size_t));
 #if __BSD_VISIBLE
 char 	*_EXFUN(strsep,(char **, const char *));
 #endif
+#if __BSD_VISIBLE
+char    *strnstr(const char *, const char *, size_t) __pure;
+#endif
 
 #if __MISC_VISIBLE
 char	*_EXFUN(strlwr,(char *));
diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am
index e62f286..f8bd41e 100644
--- a/newlib/libc/string/Makefile.am
+++ b/newlib/libc/string/Makefile.am
@@ -40,6 +40,7 @@ GENERAL_SOURCES = \
 	strncmp.c \
 	strncpy.c \
 	strnlen.c \
+	strnstr.c \
 	strpbrk.c \
 	strrchr.c \
 	strsep.c \
-- 
2.7.4



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/2] Import strnstr.c from FreeBSD.
@ 2017-08-25  7:53 Sichen Zhao
  2017-08-25  7:36 ` [PATCH v3 2/2] Port strnstr.c to newlib Sichen Zhao
  2017-08-25 17:56 ` [PATCH v3 1/2] Import strnstr.c from FreeBSD Corinna Vinschen
  0 siblings, 2 replies; 8+ messages in thread
From: Sichen Zhao @ 2017-08-25  7:53 UTC (permalink / raw)
  To: newlib; +Cc: gedare, joel, christian.mauderer, sebastian.huber, Sichen Zhao

---
 newlib/libc/string/strnstr.c | 65 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 newlib/libc/string/strnstr.c

diff --git a/newlib/libc/string/strnstr.c b/newlib/libc/string/strnstr.c
new file mode 100644
index 0000000..da5e5bd
--- /dev/null
+++ b/newlib/libc/string/strnstr.c
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/string/strnstr.c 251069 2013-05-28 20:57:40Z emaste $");
+
+#include <string.h>
+
+/*
+ * Find the first occurrence of find in s, where the search is limited to the
+ * first slen characters of s.
+ */
+char *
+strnstr(const char *s, const char *find, size_t slen)
+{
+	char c, sc;
+	size_t 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);
+}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-25  7:53 [PATCH v3 1/2] Import strnstr.c from FreeBSD Sichen Zhao
  2017-08-25  7:36 ` [PATCH v3 2/2] Port strnstr.c to newlib Sichen Zhao
@ 2017-08-25 17:56 ` Corinna Vinschen
  2017-08-25 18:07   ` Sebastian Huber
  1 sibling, 1 reply; 8+ messages in thread
From: Corinna Vinschen @ 2017-08-25 17:56 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

On Aug 25 15:35, Sichen Zhao wrote:
> ---
>  newlib/libc/string/strnstr.c | 65 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
>  create mode 100644 newlib/libc/string/strnstr.c

Patchset pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-25 17:56 ` [PATCH v3 1/2] Import strnstr.c from FreeBSD Corinna Vinschen
@ 2017-08-25 18:07   ` Sebastian Huber
  2017-08-28  8:57     ` Corinna Vinschen
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastian Huber @ 2017-08-25 18:07 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 67 bytes --]

This caused a conflict with the iconv support.  See attached patch.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-compile-error-due-to-new-strnstr.patch --]
[-- Type: text/x-patch; name=0001-Fix-compile-error-due-to-new-strnstr.patch, Size: 2310 bytes --]

From 754f598a0a0dbde072a5baa3d4c3374333326c76 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Fri, 25 Aug 2017 19:48:42 +0200
Subject: [PATCH] Fix compile error due to new strnstr()

Remove local strnstr() implementation to fix compile error:

newlib/libc/iconv/lib/aliasesi.c:53:8: error: conflicting types for 'strnstr'
 _DEFUN(strnstr, (haystack, needle, length),
        ^
In file included from newlib/libc/iconv/lib/aliasesi.c:29:0:
newlib/libc/include/string.h:125:10:
note: previous declaration of 'strnstr' was here
 char    *strnstr(const char *, const char *, size_t) __pure;
          ^~~~~~~

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
 newlib/libc/iconv/lib/aliasesi.c | 43 ----------------------------------------
 1 file changed, 43 deletions(-)

diff --git a/newlib/libc/iconv/lib/aliasesi.c b/newlib/libc/iconv/lib/aliasesi.c
index f94ac8f..41497c6 100644
--- a/newlib/libc/iconv/lib/aliasesi.c
+++ b/newlib/libc/iconv/lib/aliasesi.c
@@ -34,49 +34,6 @@
 #include "local.h"
 
 /*
- * strnstr - locate a substring in a fixed-size string.
- *
- * PARAMETERS:
- *   _CONST char *haystack - the string in which to search.
- *   _CONST char *needle   - the string which to search.
- *   int length            - the maximum 'haystack' string length.
- *
- * DESCRIPTION:
- *   The  strstr() function finds the first occurrence of the substring 
- *   'needle' in the string 'haystack'. At most 'length' bytes are searched.
- *
- * RETURN:
- *   Returns a pointer to the beginning of substring, or NULL if substring
- *   was not found.
- */
-static char *
-_DEFUN(strnstr, (haystack, needle, length),
-                _CONST char *haystack _AND
-                _CONST char *needle   _AND
-                int length)
-{
-  _CONST char *max = haystack + length;
-
-  if (*haystack == '\0')
-    return *needle == '\0' ? (char *)haystack : (char *)NULL;
-
-  while (haystack < max)
-    {
-      int i = 0;
-      while (1)
-        {
-          if (needle[i] == '\0')
-            return (char *)haystack;
-          if (needle[i] != haystack[i])
-            break;
-          i += 1;
-        }
-      haystack += 1;
-    }
-  return (char *)NULL;
-}
-
-/*
  * canonical_form - canonize 'str'.
  *
  * PARAMETERS:
-- 
1.8.1.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-25 18:07   ` Sebastian Huber
@ 2017-08-28  8:57     ` Corinna Vinschen
  2017-08-28 14:43       ` Sebastian Huber
  2017-08-28 14:59       ` Sebastian Huber
  0 siblings, 2 replies; 8+ messages in thread
From: Corinna Vinschen @ 2017-08-28  8:57 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]

On Aug 25 19:56, Sebastian Huber wrote:
> This caused a conflict with the iconv support.  See attached patch.

> From 754f598a0a0dbde072a5baa3d4c3374333326c76 Mon Sep 17 00:00:00 2001
> From: Sebastian Huber <sebastian.huber@embedded-brains.de>
> Date: Fri, 25 Aug 2017 19:48:42 +0200
> Subject: [PATCH] Fix compile error due to new strnstr()
> 
> Remove local strnstr() implementation to fix compile error:
> 
> newlib/libc/iconv/lib/aliasesi.c:53:8: error: conflicting types for 'strnstr'
>  _DEFUN(strnstr, (haystack, needle, length),
>         ^
> In file included from newlib/libc/iconv/lib/aliasesi.c:29:0:
> newlib/libc/include/string.h:125:10:
> note: previous declaration of 'strnstr' was here
>  char    *strnstr(const char *, const char *, size_t) __pure;
>           ^~~~~~~
> 
> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> ---
>  newlib/libc/iconv/lib/aliasesi.c | 43 ----------------------------------------

Thanks for catching, please push.


Corinna


-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-28  8:57     ` Corinna Vinschen
@ 2017-08-28 14:43       ` Sebastian Huber
  2017-08-28 15:43         ` Corinna Vinschen
  2017-08-28 14:59       ` Sebastian Huber
  1 sibling, 1 reply; 8+ messages in thread
From: Sebastian Huber @ 2017-08-28 14:43 UTC (permalink / raw)
  To: newlib


----- Corinna Vinschen <vinschen@redhat.com> schrieb:
> On Aug 25 19:56, Sebastian Huber wrote:
> > This caused a conflict with the iconv support.  See attached patch.
> 
> > From 754f598a0a0dbde072a5baa3d4c3374333326c76 Mon Sep 17 00:00:00 2001
> > From: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > Date: Fri, 25 Aug 2017 19:48:42 +0200
> > Subject: [PATCH] Fix compile error due to new strnstr()
> > 
> > Remove local strnstr() implementation to fix compile error:
> > 
> > newlib/libc/iconv/lib/aliasesi.c:53:8: error: conflicting types for 'strnstr'
> >  _DEFUN(strnstr, (haystack, needle, length),
> >         ^
> > In file included from newlib/libc/iconv/lib/aliasesi.c:29:0:
> > newlib/libc/include/string.h:125:10:
> > note: previous declaration of 'strnstr' was here
> >  char    *strnstr(const char *, const char *, size_t) __pure;
> >           ^~~~~~~
> > 
> > Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > ---
> >  newlib/libc/iconv/lib/aliasesi.c | 43 ----------------------------------------
> 
> Thanks for catching, please push.

 I am on holidays this week and don't have access to my SSH key.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine gesch&auml;ftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-28  8:57     ` Corinna Vinschen
  2017-08-28 14:43       ` Sebastian Huber
@ 2017-08-28 14:59       ` Sebastian Huber
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastian Huber @ 2017-08-28 14:59 UTC (permalink / raw)
  To: newlib


----- Corinna Vinschen <vinschen@redhat.com> schrieb:
> On Aug 25 19:56, Sebastian Huber wrote:
> > This caused a conflict with the iconv support.  See attached patch.
> 
> > From 754f598a0a0dbde072a5baa3d4c3374333326c76 Mon Sep 17 00:00:00 2001
> > From: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > Date: Fri, 25 Aug 2017 19:48:42 +0200
> > Subject: [PATCH] Fix compile error due to new strnstr()
> > 
> > Remove local strnstr() implementation to fix compile error:
> > 
> > newlib/libc/iconv/lib/aliasesi.c:53:8: error: conflicting types for 'strnstr'
> >  _DEFUN(strnstr, (haystack, needle, length),
> >         ^
> > In file included from newlib/libc/iconv/lib/aliasesi.c:29:0:
> > newlib/libc/include/string.h:125:10:
> > note: previous declaration of 'strnstr' was here
> >  char    *strnstr(const char *, const char *, size_t) __pure;
> >           ^~~~~~~
> > 
> > Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > ---
> >  newlib/libc/iconv/lib/aliasesi.c | 43 ----------------------------------------
> 
> Thanks for catching, please push.

 I am on holidays this week and don't have access to my SSH key.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine gesch&auml;ftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/2] Import strnstr.c from FreeBSD.
  2017-08-28 14:43       ` Sebastian Huber
@ 2017-08-28 15:43         ` Corinna Vinschen
  0 siblings, 0 replies; 8+ messages in thread
From: Corinna Vinschen @ 2017-08-28 15:43 UTC (permalink / raw)
  To: Sebastian Huber; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

On Aug 28 16:43, Sebastian Huber wrote:
> 
> ----- Corinna Vinschen <vinschen@redhat.com> schrieb:
> > On Aug 25 19:56, Sebastian Huber wrote:
> > > This caused a conflict with the iconv support.  See attached patch.
> > 
> > > From 754f598a0a0dbde072a5baa3d4c3374333326c76 Mon Sep 17 00:00:00 2001
> > > From: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > > Date: Fri, 25 Aug 2017 19:48:42 +0200
> > > Subject: [PATCH] Fix compile error due to new strnstr()
> > > 
> > > Remove local strnstr() implementation to fix compile error:
> > > 
> > > newlib/libc/iconv/lib/aliasesi.c:53:8: error: conflicting types for 'strnstr'
> > >  _DEFUN(strnstr, (haystack, needle, length),
> > >         ^
> > > In file included from newlib/libc/iconv/lib/aliasesi.c:29:0:
> > > newlib/libc/include/string.h:125:10:
> > > note: previous declaration of 'strnstr' was here
> > >  char    *strnstr(const char *, const char *, size_t) __pure;
> > >           ^~~~~~~
> > > 
> > > Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> > > ---
> > >  newlib/libc/iconv/lib/aliasesi.c | 43 ----------------------------------------
> > 
> > Thanks for catching, please push.
> 
>  I am on holidays this week and don't have access to my SSH key.

No worries.  Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-08-28 15:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25  7:53 [PATCH v3 1/2] Import strnstr.c from FreeBSD Sichen Zhao
2017-08-25  7:36 ` [PATCH v3 2/2] Port strnstr.c to newlib Sichen Zhao
2017-08-25 17:56 ` [PATCH v3 1/2] Import strnstr.c from FreeBSD Corinna Vinschen
2017-08-25 18:07   ` Sebastian Huber
2017-08-28  8:57     ` Corinna Vinschen
2017-08-28 14:43       ` Sebastian Huber
2017-08-28 15:43         ` Corinna Vinschen
2017-08-28 14:59       ` Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).