source: azure_iot_hub/trunk/musl-1.1.18/src/string/memchr.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 619 bytes
Line 
1#include <string.h>
2#include <stdint.h>
3#include <limits.h>
4
5#define SS (sizeof(size_t))
6#define ALIGN (sizeof(size_t)-1)
7#define ONES ((size_t)-1/UCHAR_MAX)
8#define HIGHS (ONES * (UCHAR_MAX/2+1))
9#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
10
11void *memchr(const void *src, int c, size_t n)
12{
13 const unsigned char *s = src;
14 c = (unsigned char)c;
15 for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
16 if (n && *s != c) {
17 const size_t *w;
18 size_t k = ONES * c;
19 for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
20 for (s = (const void *)w; n && *s != c; s++, n--);
21 }
22 return n ? (void *)s : 0;
23}
Note: See TracBrowser for help on using the repository browser.