summaryrefslogtreecommitdiff
path: root/src/string/strstr.c
blob: 4a8d9767d3fabe267f8c6d76b8fc9b01a6cb3031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#if 0

#include <string.h>
#include "_assert.h"

/** search for substring **/

char * strstr(const char *s1, const char *s2)
{
	size_t l1 = 0;
	size_t l2 = 0;
	char *p = (char*)s1;

	ASSERT_NONNULL(s1);
	ASSERT_NONNULL(s2);

	l1 = strlen(s1);
	l2 = strlen(s2);
	
	for (p = (char*)s1; p < s1 + l1 - l2; p = strchr(p + 1, *s2)) {
		if (p == NULL || strncmp(p, s2, l2) == 0) {
			break;
		}
	}

	/*
	RETURN_FAILURE(CONSTANT(NULL));
	RETURN_SUCCESS(a pointer to the located string);
	*/
	return p;
}

/***
finds the first occurrence of the string ARGUMENT(s2) in the string
ARGUMENT(s1). Specifying the empty string for ARGUMENT(s2) matches the first
character of ARGUMENT(s1).
***/

/*
STDC(1)
*/


#endif