11 #define LONG_BIT (CHAR_BIT*sizeof(long))
14 static void set_bit(unsigned long *bitmap
, unsigned int bit
)
16 bitmap
[bit
/ LONG_BIT
] |= 1UL << (bit
% LONG_BIT
);
19 static int test_bit(unsigned long *bitmap
, unsigned int bit
)
21 return (int)(bitmap
[bit
/ LONG_BIT
] >> (bit
% LONG_BIT
)) & 1;
24 static size_t strxspn(const char *s
, const char *map
, int parity
)
26 unsigned long matchmap
[((1 << CHAR_BIT
) + LONG_BIT
- 1) / LONG_BIT
];
30 memset(matchmap
, 0, sizeof matchmap
);
32 set_bit(matchmap
, (unsigned char)*map
++);
34 /* Make sure the null character never matches */
38 /* Calculate span length */
39 while (test_bit(matchmap
, (unsigned char)*s
++) ^ parity
)
45 size_t strspn(const char *s
, const char *accept
)
47 return strxspn(s
, accept
, 0);
50 size_t strcspn(const char *s
, const char *reject
)
52 return strxspn(s
, reject
, 1);
55 char *strpbrk(const char *s
, const char *accept
)
57 const char *ss
= s
+ strxspn(s
, accept
, 1);
59 return *ss
? (char *)ss
: NULL
;