[PSDK]
[reactos.git] / reactos / lib / sdk / crt / string / strpbrk.c
1 /*
2 * $Id$
3 */
4 #include <limits.h>
5 #include <string.h>
6
7 #define BIT_SIZE (CHAR_BIT * sizeof(unsigned long) / sizeof(char))
8
9 char* strpbrk(const char *s1, const char *s2)
10 {
11 if (*s2 == 0)
12 {
13 return 0;
14 }
15 if (*(s2+1) == 0)
16 {
17 return strchr(s1, *s2);
18 }
19 else if (*(s2+2) == 0)
20 {
21 char *s3, *s4;
22 s3 = strchr(s1, *s2);
23 s4 = strchr(s1, *(s2+1));
24 if (s3 == 0)
25 {
26 return s4;
27 }
28 else if (s4 == 0)
29 {
30 return s3;
31 }
32 return s3 < s4 ? s3 : s4;
33 }
34 else
35 {
36 unsigned long char_map[(1 << CHAR_BIT) / BIT_SIZE] = {0, };
37 const unsigned char* str = (const unsigned char*)s1;
38 while (*s2)
39 {
40 char_map[*(const unsigned char*)s2 / BIT_SIZE] |= (1 << (*(const unsigned char*)s2 % BIT_SIZE));
41 s2++;
42 }
43 while (*str)
44 {
45 if (char_map[*str / BIT_SIZE] & (1 << (*str % BIT_SIZE)))
46 {
47 return (char*)((size_t)str);
48 }
49 str++;
50 }
51 }
52 return 0;
53 }
54