|
Last change
on this file since 1816 was 1816, checked in by bird, 16 years ago |
|
kmk: windows build fix.
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | #include <string.h>
|
|---|
| 2 | #ifdef _MSC_VER
|
|---|
| 3 | _inline void *
|
|---|
| 4 | #else
|
|---|
| 5 | static __inline__ void *
|
|---|
| 6 | #endif
|
|---|
| 7 | my_inline_memchr(const void *pv, int ch, register size_t cb)
|
|---|
| 8 | {
|
|---|
| 9 | register const unsigned int uch = (unsigned)ch;
|
|---|
| 10 | register const unsigned char *pb = (const unsigned char *)pv;
|
|---|
| 11 | #if 1
|
|---|
| 12 | while (cb >= 4)
|
|---|
| 13 | {
|
|---|
| 14 | if (*pb == uch)
|
|---|
| 15 | return (unsigned char *)pb;
|
|---|
| 16 | if (pb[1] == uch)
|
|---|
| 17 | return (unsigned char *)pb + 1;
|
|---|
| 18 | if (pb[2] == uch)
|
|---|
| 19 | return (unsigned char *)pb + 2;
|
|---|
| 20 | if (pb[3] == uch)
|
|---|
| 21 | return (unsigned char *)pb + 3;
|
|---|
| 22 | cb -= 4;
|
|---|
| 23 | pb += 4;
|
|---|
| 24 | }
|
|---|
| 25 | switch (cb & 3)
|
|---|
| 26 | {
|
|---|
| 27 | case 0:
|
|---|
| 28 | break;
|
|---|
| 29 | case 1:
|
|---|
| 30 | if (*pb == uch)
|
|---|
| 31 | return (unsigned char *)pb;
|
|---|
| 32 | break;
|
|---|
| 33 | case 2:
|
|---|
| 34 | if (*pb == uch)
|
|---|
| 35 | return (unsigned char *)pb;
|
|---|
| 36 | if (pb[1] == uch)
|
|---|
| 37 | return (unsigned char *)pb + 1;
|
|---|
| 38 | break;
|
|---|
| 39 | case 3:
|
|---|
| 40 | if (*pb == uch)
|
|---|
| 41 | return (unsigned char *)pb;
|
|---|
| 42 | if (pb[1] == uch)
|
|---|
| 43 | return (unsigned char *)pb + 1;
|
|---|
| 44 | if (pb[2] == uch)
|
|---|
| 45 | return (unsigned char *)pb + 2;
|
|---|
| 46 | break;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | #else
|
|---|
| 50 | while (cb > 0)
|
|---|
| 51 | {
|
|---|
| 52 | if (*pb == uch)
|
|---|
| 53 | return (void *)pb;
|
|---|
| 54 | cb--;
|
|---|
| 55 | pb++;
|
|---|
| 56 | }
|
|---|
| 57 | #endif
|
|---|
| 58 | return 0;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | #define memchr my_inline_memchr
|
|---|
| 62 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.