1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12 
13 #include <stddef.h>
14 
15 size_t strlen(const char *s);
16 int strncmp(const char *s1, const char *s2, size_t n);
17 char *strstr(const char *hay, const char *needle);
strstr(const char * hay,const char * needle)18 char *strstr(const char *hay, const char *needle)
19 {
20 	char *pos;
21 	size_t hlen, nlen;
22 
23 	if (hay == NULL || needle == NULL)
24 		return NULL;
25 
26 	hlen = strlen(hay);
27 	nlen = strlen(needle);
28 	if (nlen < 1)
29 		return (char *)hay;
30 
31 	for (pos = (char *)hay; pos < hay + hlen; pos++) {
32 		if (strncmp(pos, needle, nlen) == 0) {
33 			return pos;
34 		}
35 	}
36 
37 	return NULL;
38 }
39 
40