PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
strcspn.c
1#define SYSCLIB_DISABLE_BUILTINS
2#include <sysclib.h>
3
4char *__strchrnul(const char *s, int c);
5
6#define BITOP(a,b,op) \
7 ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
8
9size_t strcspn(const char *s, const char *c)
10{
11 const char *a = s;
12 size_t byteset[32/sizeof(size_t)];
13
14 if (!c[0] || !c[1]) return __strchrnul(s, *c)-a;
15
16 memset(byteset, 0, sizeof byteset);
17 for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
18 for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
19 return s-a;
20}