aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/string/memchr.c
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2020-11-18 22:01:34 +0000
committerEd Maste <emaste@FreeBSD.org>2020-11-18 22:01:34 +0000
commit4874ddfd373c582d9cd7fe915d2259295d75d1e5 (patch)
tree273fb1be4959f2cf997973cc8343d3aae15939fc /lib/libc/string/memchr.c
parentf488d5b79787e06a5c82acde518a289907ba395c (diff)
Notes
Diffstat (limited to 'lib/libc/string/memchr.c')
-rw-r--r--lib/libc/string/memchr.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/libc/string/memchr.c b/lib/libc/string/memchr.c
index d89d097752725..4b5d6f6a4c8a0 100644
--- a/lib/libc/string/memchr.c
+++ b/lib/libc/string/memchr.c
@@ -25,30 +25,35 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <string.h>
-#include <stdint.h>
#include <limits.h>
+#include <stdint.h>
+#include <string.h>
#define SS (sizeof(size_t))
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
+#define ALIGN (sizeof(size_t) - 1)
+#define ONES ((size_t)-1 / UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
+#define HASZERO(x) (((x)-ONES) & ~(x)&HIGHS)
-void *memchr(const void *src, int c, size_t n)
+void *
+memchr(const void *src, int c, size_t n)
{
const unsigned char *s = src;
c = (unsigned char)c;
#ifdef __GNUC__
- for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
+ for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--)
+ ;
if (n && *s != c) {
typedef size_t __attribute__((__may_alias__)) word;
const word *w;
size_t k = ONES * c;
- for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
+ for (w = (const void *)s; n >= SS && !HASZERO(*w ^ k);
+ w++, n -= SS)
+ ;
s = (const void *)w;
}
#endif
- for (; n && *s != c; s++, n--);
+ for (; n && *s != c; s++, n--)
+ ;
return n ? (void *)s : 0;
}