summaryrefslogtreecommitdiff
path: root/libc/string/strstr.c
diff options
context:
space:
mode:
authorProjectRevoTPP <projectrevotpp@hotmail.com>2017-12-20 16:34:35 -0500
committerProjectRevoTPP <projectrevotpp@hotmail.com>2017-12-20 16:34:35 -0500
commit48ef7704c03e7e554c05de01bf8d1d70c16cb6f4 (patch)
tree34d52513de6c903b4f52ef87d885c73472daf469 /libc/string/strstr.c
parentf49e7cbb33e6e27b0ce5eb35244d7241c800a7c1 (diff)
add libc building to agbcc.
Diffstat (limited to 'libc/string/strstr.c')
-rw-r--r--libc/string/strstr.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/libc/string/strstr.c b/libc/string/strstr.c
new file mode 100644
index 0000000..dddced3
--- /dev/null
+++ b/libc/string/strstr.c
@@ -0,0 +1,73 @@
+/*
+FUNCTION
+ <<strstr>>---find string segment
+
+INDEX
+ strstr
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ char *strstr(const char *<[s1]>, const char *<[s2]>);
+
+TRAD_SYNOPSIS
+ #include <string.h>
+ char *strstr(<[s1]>, <[s2]>)
+ char *<[s1]>;
+ char *<[s2]>;
+
+DESCRIPTION
+ Locates the first occurence in the string pointed to by <[s1]> of
+ the sequence of characters in the string pointed to by <[s2]>
+ (excluding the terminating null character).
+
+RETURNS
+ Returns a pointer to the located string segment, or a null
+ pointer if the string <[s2]> is not found. If <[s2]> points to
+ a string with zero length, the <[s1]> is returned.
+
+PORTABILITY
+<<strstr>> is ANSI C.
+
+<<strstr>> requires no supporting OS subroutines.
+
+QUICKREF
+ strstr ansi pure
+*/
+
+#include <string.h>
+
+char *
+_DEFUN (strstr, (searchee, lookfor),
+ _CONST char *searchee _AND
+ _CONST char *lookfor)
+{
+ if (*searchee == 0)
+ {
+ if (*lookfor)
+ return (char *) NULL;
+ return (char *) searchee;
+ }
+
+ while (*searchee)
+ {
+ size_t i;
+ i = 0;
+
+ while (1)
+ {
+ if (lookfor[i] == 0)
+ {
+ return (char *) searchee;
+ }
+
+ if (lookfor[i] != searchee[i])
+ {
+ break;
+ }
+ i++;
+ }
+ searchee++;
+ }
+
+ return (char *) NULL;
+}