[hackers] [scc] [libc] Add strstr() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 23 Feb 2017 16:18:00 +0100 (CET)

commit df779ca3586630480a25c17a14b1a8c2e1cd6dd8
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Feb 23 15:16:38 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Feb 23 16:17:51 2017 +0100

    [libc] Add strstr()

diff --git a/libc/src/Makefile b/libc/src/Makefile
index e8612df..2984f58 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -3,7 +3,7 @@
 
 LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
           strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
- strxfrm.o strtok.o \
+ strxfrm.o strtok.o strstr.o \
           memset.o memcpy.o memmove.o memcmp.o memchr.o \
           isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
           isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
diff --git a/libc/src/strstr.c b/libc/src/strstr.c
new file mode 100644
index 0000000..bc3277a
--- /dev/null
+++ b/libc/src/strstr.c
_AT_@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+char *
+strstr(const char *s1, const char *s2)
+{
+ const char *p, *q;
+ int c;
+
+ c = *s2++;
+ if (c == '\0')
+ return (char *) s1;
+
+ while (*s1) {
+ if (*s1 != c) {
+ ++s;
+ } else {
+ p = s1++;
+ for (q = s2; *q && *s1 == *q; ++s1, ++q)
+ /* nothing */;
+ if (*q == '\0')
+ return (char *) p;
+ }
+ }
+ return NULL;
+}
Received on Thu Feb 23 2017 - 16:18:00 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 23 2017 - 16:24:30 CET