diff options
Diffstat (limited to 'firmware/libc/strcspn.c')
-rw-r--r-- | firmware/libc/strcspn.c | 45 |
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 | /* | ||
2 | FUNCTION | ||
3 | <<strcspn>>---count characters not in string | ||
4 | INDEX | ||
5 | strcspn | ||
6 | ANSI_SYNOPSIS | ||
7 | size_t strcspn(const char *<[s1]>, const char *<[s2]>); | ||
8 | TRAD_SYNOPSIS | ||
9 | size_t strcspn(<[s1]>, <[s2]>) | ||
10 | char *<[s1]>; | ||
11 | char *<[s2]>; | ||
12 | DESCRIPTION | ||
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). | ||
17 | RETURNS | ||
18 | <<strcspn>> returns the length of the substring found. | ||
19 | PORTABILITY | ||
20 | <<strcspn>> is ANSI C. | ||
21 | <<strcspn>> requires no supporting OS subroutines. | ||
22 | */ | ||
23 | #include <string.h> | ||
24 | #include "_ansi.h" /* for _DEFUN */ | ||
25 | |||
26 | size_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 | } | ||