Last change
on this file was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
788 bytes
|
Rev | Line | |
---|
[444] | 1 | /* |
---|
| 2 | FUNCTION |
---|
| 3 | <<strcspn>>---count characters not in string |
---|
| 4 | |
---|
| 5 | INDEX |
---|
| 6 | strcspn |
---|
| 7 | |
---|
| 8 | SYNOPSIS |
---|
| 9 | size_t strcspn(const char *<[s1]>, const char *<[s2]>); |
---|
| 10 | |
---|
| 11 | DESCRIPTION |
---|
| 12 | This function computes the length of the initial part of |
---|
| 13 | the string pointed to by <[s1]> which consists entirely of |
---|
| 14 | characters <[NOT]> from the string pointed to by <[s2]> |
---|
| 15 | (excluding the terminating null character). |
---|
| 16 | |
---|
| 17 | RETURNS |
---|
| 18 | <<strcspn>> returns the length of the substring found. |
---|
| 19 | |
---|
| 20 | PORTABILITY |
---|
| 21 | <<strcspn>> is ANSI C. |
---|
| 22 | |
---|
| 23 | <<strcspn>> requires no supporting OS subroutines. |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <string.h> |
---|
| 27 | |
---|
| 28 | size_t |
---|
| 29 | strcspn (const char *s1, |
---|
| 30 | const char *s2) |
---|
| 31 | { |
---|
| 32 | const char *s = s1; |
---|
| 33 | const char *c; |
---|
| 34 | |
---|
| 35 | while (*s1) |
---|
| 36 | { |
---|
| 37 | for (c = s2; *c; c++) |
---|
| 38 | { |
---|
| 39 | if (*s1 == *c) |
---|
| 40 | break; |
---|
| 41 | } |
---|
| 42 | if (*c) |
---|
| 43 | break; |
---|
| 44 | s1++; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | return s1 - s; |
---|
| 48 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.