* [PATCH v2 2/2] Port strnstr.c to newlib.
2017-08-25 6:21 [PATCH v2 1/2] Import strnstr.c from FreeBSD Sichen Zhao
@ 2017-08-25 6:16 ` Sichen Zhao
2017-08-25 7:23 ` Sebastian Huber
0 siblings, 1 reply; 4+ messages in thread
From: Sichen Zhao @ 2017-08-25 6:16 UTC (permalink / raw)
To: newlib; +Cc: gedare, joel, christian.mauderer, Sichen Zhao
---
newlib/libc/include/string.h | 3 +++
newlib/libc/string/Makefile.am | 1 +
newlib/libc/string/strnstr.c | 13 ++++++-------
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
index 7833aa1..304d8a5 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 *_EXFUN(strnstr,(const char *, const char *, size_t));
+#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 \
diff --git a/newlib/libc/string/strnstr.c b/newlib/libc/string/strnstr.c
index 4de757d..8903200 100644
--- a/newlib/libc/string/strnstr.c
+++ b/newlib/libc/string/strnstr.c
@@ -31,12 +31,8 @@
* 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$");
-
+#undef __STRICT_ANSI__
+#include <_ansi.h>
#include <string.h>
/*
@@ -44,7 +40,10 @@ __FBSDID("$FreeBSD$");
* first slen characters of s.
*/
char *
-strnstr(const char *s, const char *find, size_t slen)
+_DEFUN (strnstr, (s, find, slen),
+ _CONST char *s _AND
+ _CONST char *find _AND
+ size_t slen)
{
char c, sc;
size_t len;
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] Import strnstr.c from FreeBSD.
@ 2017-08-25 6:21 Sichen Zhao
2017-08-25 6:16 ` [PATCH v2 2/2] Port strnstr.c to newlib Sichen Zhao
0 siblings, 1 reply; 4+ messages in thread
From: Sichen Zhao @ 2017-08-25 6:21 UTC (permalink / raw)
To: newlib; +Cc: gedare, joel, christian.mauderer, 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..4de757d
--- /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$");
+
+#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] 4+ messages in thread
* Re: [PATCH v2 2/2] Port strnstr.c to newlib.
2017-08-25 6:16 ` [PATCH v2 2/2] Port strnstr.c to newlib Sichen Zhao
@ 2017-08-25 7:23 ` Sebastian Huber
2017-08-25 7:36 ` Sichen Zhao
0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Huber @ 2017-08-25 7:23 UTC (permalink / raw)
To: Sichen Zhao, newlib; +Cc: gedare, joel, christian.mauderer
On 25/08/17 08:15, Sichen Zhao wrote:
> ---
> newlib/libc/include/string.h | 3 +++
> newlib/libc/string/Makefile.am | 1 +
> newlib/libc/string/strnstr.c | 13 ++++++-------
> 3 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
> index 7833aa1..304d8a5 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 *_EXFUN(strnstr,(const char *, const char *, size_t));
> +#endif
I would rather use the FreeBSD prototype:
#if __BSD_VISIBLE
char *strnstr(const char *, const char *, size_t) __pure;
#endif
This makes the strnstr.c modifications unnecessary. I think the _EXFUN()
stuff is deprecated.
--
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@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] Port strnstr.c to newlib.
2017-08-25 7:23 ` Sebastian Huber
@ 2017-08-25 7:36 ` Sichen Zhao
0 siblings, 0 replies; 4+ messages in thread
From: Sichen Zhao @ 2017-08-25 7:36 UTC (permalink / raw)
To: Sebastian Huber, newlib; +Cc: gedare, joel, christian.mauderer
> On 25/08/17 08:15, Sichen Zhao wrote:
>
>> ---
>> newlib/libc/include/string.h | 3 +++
>> newlib/libc/string/Makefile.am | 1 +
>> newlib/libc/string/strnstr.c | 13 ++++++-------
>> 3 files changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
>> index 7833aa1..304d8a5 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 *_EXFUN(strnstr,(const char *, const char *, size_t));
>> +#endif
>
> I would rather use the FreeBSD prototype:
>
> #if __BSD_VISIBLE
> char *strnstr(const char *, const char *, size_t) __pure;
> #endif
>
> This makes the strnstr.c modifications unnecessary. I think the
> _EXFUN() stuff is deprecated.
>
Ok, i see.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-08-25 7:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25 6:21 [PATCH v2 1/2] Import strnstr.c from FreeBSD Sichen Zhao
2017-08-25 6:16 ` [PATCH v2 2/2] Port strnstr.c to newlib Sichen Zhao
2017-08-25 7:23 ` Sebastian Huber
2017-08-25 7:36 ` Sichen Zhao
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).