summaryrefslogtreecommitdiff
path: root/xen/lib/strstr.c
blob: c305f5acb32b7a6d358a35b5fa0d6b108a027caf (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
/*
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */

#include <xen/string.h>

/**
 * strstr - Find the first substring in a %NUL terminated string
 * @s1: The string to be searched
 * @s2: The string to search for
 */
char *(strstr)(const char *s1, const char *s2)
{
	size_t l1, l2 = strlen(s2);

	if (!l2)
		return (char *)s1;

	for (l1 = strlen(s1); l1 >= l2; --l1, ++s1)
		if (!memcmp(s1, s2, l2))
			return (char *)s1;

	return NULL;
}

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 */