src/port.c
void *

memmem(const void *l, size_t l_len, const void *s, size_t s_len)

{

	register char *cur, *last;

	const char *cl = (const char *)l;

	const char *cs = (const char *)s;



	/* we need something to compare */

	if (l_len == 0 || s_len == 0)

		return NULL;



	/* "s" must be smaller or equal to "l" */

	if (l_len < s_len)

		return NULL;



	/* special case where s_len == 1 */

	if (s_len == 1)

		return memchr(l, (int)*cs, l_len);



	/* the last position where its possible to find "s" in "l" */

	last = (char *)cl + l_len - s_len;



	for (cur = (char *)cl; cur <= last; cur++)

		if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)

			return cur;



	return NULL;

}
/*

* Find the first occurrence of the byte string s in byte string l.

*/
Find the first occurrence of the byte string s in byte string l.
Find the first occurrence of the byte string s in byte string l .
void *
memmem(const void *l, size_t l_len, const void *s, size_t s_len)
{
	register char *cur, *last;
	const char *cl = (const char *)l;
	const char *cs = (const char *)s;
	if (l_len == 0 || s_len == 0)
		return NULL;
	if (l_len < s_len)
		return NULL;
	if (s_len == 1)
		return memchr(l, (int)*cs, l_len);
	last = (char *)cl + l_len - s_len;
	for (cur = (char *)cl; cur <= last; cur++)
		if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
			return cur;
	return NULL;
}
void * memmem ( const void * l , size_t l_len , const void * s , size_t s_len ) { register char * cur , * last ; const char * cl = ( const char * ) l ; const char * cs = ( const char * ) s ; if ( l_len == 0 || s_len == 0 ) return NULL ; if ( l_len < s_len ) return NULL ; if ( s_len == 1 ) return memchr ( l , ( int ) * cs , l_len ) ; last = ( char * ) cl + l_len - s_len ; for ( cur = ( char * ) cl ; cur <= last ; cur ++ ) if ( cur [ 0 ] == cs [ 0 ] && memcmp ( cur , cs , s_len ) == 0 ) return cur ; return NULL ; }
Find the first occurrence of the byte string s in byte string l.
Find the first occurrence of the byte string s in byte string l .
/* we need something to compare */ /* "s" must be smaller or equal to "l" */ /* special case where s_len == 1 */ /* the last position where its possible to find "s" in "l" */