Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strcspn.c
Go to the documentation of this file.
1
#include "
strchrnul.h
"
2
#include <
stdint.h
>
3
#include <
string.h
>
4
5
#define BITOP(a, b, op) \
6
((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 << ((size_t)(b) % (8 * sizeof *(a))))
7
8
size_t
strcspn
(
const
char
* s,
const
char
* c)
9
{
10
const
char
* a = s;
11
size_t
byteset[32 /
sizeof
(size_t)];
12
13
if
(!c[0] || !c[1])
14
{
15
return
(uintptr_t)(
__strchrnul
(s, *c) - (uintptr_t)a);
16
}
17
18
memset
(byteset, 0,
sizeof
byteset);
19
for
(; *c &&
BITOP
(byteset, *(
const
unsigned
char
*)c, |=); c++)
20
{
21
{
22
;
23
}
24
}
25
for
(; *s && !
BITOP
(byteset, *(
const
unsigned
char
*)s, &); s++)
26
{
27
{
28
;
29
}
30
}
31
return
(uintptr_t)s - (uintptr_t)a;
32
}
strcspn
size_t strcspn(const char *s, const char *c)
Definition:
strcspn.c:8
string.h
__strchrnul
char * __strchrnul(const char *, int)
Definition:
strchrnul.c:13
BITOP
#define BITOP(a, b, op)
Definition:
strcspn.c:5
memset
void * memset(void *dest, int c, size_t n)
Copies the value c into each of the first n characters of the object pointed to by dest.
stdint.h
strchrnul.h
src
string
strcspn.c
Generated by
1.8.15