ReactOS 0.4.15-dev-8339-g4028de8
strpbrk.c
Go to the documentation of this file.
1
2#include <limits.h>
3#include <string.h>
4
5#define BIT_SIZE (CHAR_BIT * sizeof(unsigned long) / sizeof(char))
6
7char* __cdecl strpbrk(const char *s1, const char *s2)
8{
9 if (*s2 == 0)
10 {
11 return 0;
12 }
13 if (*(s2+1) == 0)
14 {
15 return strchr(s1, *s2);
16 }
17 else if (*(s2+2) == 0)
18 {
19 char *s3, *s4;
20 s3 = strchr(s1, *s2);
21 s4 = strchr(s1, *(s2+1));
22 if (s3 == 0)
23 {
24 return s4;
25 }
26 else if (s4 == 0)
27 {
28 return s3;
29 }
30 return s3 < s4 ? s3 : s4;
31 }
32 else
33 {
34 unsigned long char_map[(1 << CHAR_BIT) / BIT_SIZE] = {0, };
35 const unsigned char* str = (const unsigned char*)s1;
36 while (*s2)
37 {
38 char_map[*(const unsigned char*)s2 / BIT_SIZE] |= (1 << (*(const unsigned char*)s2 % BIT_SIZE));
39 s2++;
40 }
41 while (*str)
42 {
43 if (char_map[*str / BIT_SIZE] & (1 << (*str % BIT_SIZE)))
44 {
45 return (char*)((size_t)str);
46 }
47 str++;
48 }
49 }
50 return 0;
51}
52
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define __cdecl
Definition: accygwin.h:79
#define CHAR_BIT
Definition: urlcache.c:62
__kernel_size_t size_t
Definition: linux.h:237
struct S1 s1
struct S2 s2
const WCHAR * str
char *__cdecl strpbrk(const char *s1, const char *s2)
Definition: strpbrk.c:7
#define BIT_SIZE
Definition: strpbrk.c:5