summaryrefslogtreecommitdiff
path: root/src/string/memchr.c
blob: aac59df0fec16f579dbfd8810d0a294db59f8410 (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
35
36
37
#include <string.h>
#include "_safety.h"

/** search memory **/

void * memchr(const void *s, int c, size_t n)
{
	SIGNAL_SAFE(0);

	char *p = (char*)s;
	size_t i = 0;

	ASSERT_NONNULL(s);

	for (i = 0; i < n; i++) {
		if (p[i] == (unsigned char)c) {
			return p + i;
		}
	}

	/*
	RETURN_FAILURE(CONSTANT(NULL));
	RETURN_SUCCESS(a pointer to the located byte);
	*/
	return NULL;
}

CHECK_3(void *, 0, memchr, const void *, int, size_t)

/***
searches the first ARGUMENT(n) bytes of memory at ARGUMENT(s) for
ARGUMENT(c) (converted to an TYPE(unsigned char)).
***/

/*
STDC(1)
*/