Index: contrib/netbsd-tests/lib/libc/string/t_memmem.c =================================================================== --- contrib/netbsd-tests/lib/libc/string/t_memmem.c +++ contrib/netbsd-tests/lib/libc/string/t_memmem.c @@ -75,7 +75,7 @@ ATF_TC_BODY(memmem_basic, tc) { -#if defined(__darwin__) || defined(__FreeBSD__) +#if defined(__darwin__) expect(memmem(b2, lb2, p0, lp0) == NULL); expect(memmem(b0, lb0, p0, lp0) == NULL); #else Index: lib/libc/string/memmem.c =================================================================== --- lib/libc/string/memmem.c +++ lib/libc/string/memmem.c @@ -42,9 +42,9 @@ 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; + /* empty "s" matches the beginning of "l" */ + if (s_len == 0) + return l; /* "s" must be smaller or equal to "l" */ if (l_len < s_len)