Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: fusl/src/string/strchrnul.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/string/strchr.c ('k') | fusl/src/string/strcmp.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <string.h>
2 #include <stdint.h>
3 #include <limits.h>
4 #include "libc.h"
5
6 #define ALIGN (sizeof(size_t))
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
11 char *__strchrnul(const char *s, int c)
12 {
13 size_t *w, k;
14
15 c = (unsigned char)c;
16 if (!c) return (char *)s + strlen(s);
17
18 for (; (uintptr_t)s % ALIGN; s++)
19 if (!*s || *(unsigned char *)s == c) return (char *)s;
20 k = ONES * c;
21 for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
22 for (s = (void *)w; *s && *(unsigned char *)s != c; s++);
23 return (char *)s;
24 }
25
26 weak_alias(__strchrnul, strchrnul);
OLDNEW
« no previous file with comments | « fusl/src/string/strchr.c ('k') | fusl/src/string/strcmp.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698