aboutsummaryrefslogtreecommitdiffstats
path: root/src/mem/memmem.c
blob: 68060cdca8cb86bf7b5e18785ad31a47334e038c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Copyright (c) 2023 Marc Pervaz Boocha
 *
 * SPDX-License-Identifier: MIT
 */

#include <mem.h>

void *calt_memmem(void const *haystack, size_t haystacklen,
		       void const *needle, size_t needlelen) {
	unsigned char const *p = haystack;
	unsigned char const *end = p + haystacklen - needlelen;
	while (p <= end) {
		if (calt_memcmp(p, needle, needlelen) == 0) {
			return (void *)p;
		}
		p++;
	}
	return NULL;
}