summaryrefslogtreecommitdiff
path: root/src/string/strcspn.c
blob: c157f66378e9a005b67d741f576c4c6d6bc09fb6 (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
#include <string.h>
#include "_safety.h"

/** count non-matching characters **/

size_t strcspn(const char *s1, const char *s2)
{
	size_t i = 0;

	SIGNAL_SAFE(0);
	ASSERT_NONNULL(s1);
	ASSERT_NONNULL(s2);

	/* TODO: two dangerous reads */
	/* no modification, overlap is OK */

	for (i = 0; s1[i] != '\0'; i++) {
		if (strchr (s2, s1[i]) != NULL) {
			break;
		}
	}

	return i;
}

CHECK_2(size_t, 0, strcspn, const char *, const char *)

/***
the number of characters that the beginning of
the string ARGUMENT(s1) that are not in the string ARGUMENT(s2).
***/

/*
RETURN_ALWAYS(the number of non-matching characters);
STDC(1)
*/