summaryrefslogtreecommitdiff
path: root/firmware/libc/strcspn.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/libc/strcspn.c')
-rw-r--r--firmware/libc/strcspn.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/firmware/libc/strcspn.c b/firmware/libc/strcspn.c
new file mode 100644
index 0000000000..ee50066ed1
--- /dev/null
+++ b/firmware/libc/strcspn.c
@@ -0,0 +1,45 @@
1/*
2FUNCTION
3 <<strcspn>>---count characters not in string
4INDEX
5 strcspn
6ANSI_SYNOPSIS
7 size_t strcspn(const char *<[s1]>, const char *<[s2]>);
8TRAD_SYNOPSIS
9 size_t strcspn(<[s1]>, <[s2]>)
10 char *<[s1]>;
11 char *<[s2]>;
12DESCRIPTION
13 This function computes the length of the initial part of
14 the string pointed to by <[s1]> which consists entirely of
15 characters <[NOT]> from the string pointed to by <[s2]>
16 (excluding the terminating null character).
17RETURNS
18 <<strcspn>> returns the length of the substring found.
19PORTABILITY
20<<strcspn>> is ANSI C.
21<<strcspn>> requires no supporting OS subroutines.
22 */
23#include <string.h>
24#include "_ansi.h" /* for _DEFUN */
25
26size_t
27_DEFUN (strcspn, (s1, s2),
28 _CONST char *s1 _AND
29 _CONST char *s2)
30{
31 _CONST char *s = s1;
32 _CONST char *c;
33 while (*s1)
34 {
35 for (c = s2; *c; c++)
36 {
37 if (*s1 == *c)
38 break;
39 }
40 if (*c)
41 break;
42 s1++;
43 }
44 return s1 - s;
45}