Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
Main Page
Related Pages
+
Classes
Class List
Class Index
+
Class Members
+
All
_
c
d
e
f
g
i
k
l
m
n
p
q
r
s
t
w
x
+
Variables
_
c
d
e
f
g
i
k
l
m
n
p
q
r
s
t
w
x
+
Files
File List
+
File Members
+
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
+
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
p
q
r
s
t
u
v
w
+
Variables
_
b
c
d
e
f
h
i
l
n
p
t
v
w
+
Typedefs
_
a
b
c
d
f
i
j
n
s
t
u
v
w
Enumerator
+
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
•
All
Classes
Files
Functions
Variables
Typedefs
Enumerator
Macros
Pages
strchrnul.c
Go to the documentation of this file.
1
// Imported from musl Libc
2
3
#include "
strchrnul.h
"
4
#include <
limits.h
>
5
#include <
stdint.h
>
6
#include <
string.h
>
7
8
#define ALIGN (sizeof(size_t))
9
#define ONES ((size_t)-1 / UCHAR_MAX)
10
#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
11
#define HASZERO(x) ((x)-ONES & ~(x)&HIGHS)
12
13
char
*
__strchrnul
(
const
char
* s,
int
c)
14
{
15
const
size_t
* w;
16
size_t
k;
17
c = (
unsigned
char)c;
18
19
if
(!c)
20
{
21
return
(
char
*)(uintptr_t)s +
strlen
(s);
22
}
23
24
for
(; (uintptr_t)s %
ALIGN
; s++)
25
{
26
if
(!*s || *(
const
unsigned
char
*)s == c)
27
{
28
return
(
char
*)(uintptr_t)s;
29
}
30
}
31
32
k =
ONES
* (
unsigned
long)c;
33
34
for
(w = (
const
void
*)s; !
HASZERO
(*w) && !
HASZERO
(*w ^ k); w++)
35
{
36
{
37
;
38
}
39
}
40
for
(s = (
const
void
*)w; *s && *(
const
unsigned
char
*)s != c; s++)
41
{
42
{
43
;
44
}
45
}
46
47
return
(
char
*)(uintptr_t)s;
48
}
string.h
HASZERO
#define HASZERO(x)
Definition:
strchrnul.c:11
ONES
#define ONES
Definition:
strchrnul.c:9
strlen
size_t strlen(const char *str)
Returns the length of the given null-terminated byte string.
Definition:
strlen.c:77
stdint.h
ALIGN
#define ALIGN
Definition:
strchrnul.c:8
limits.h
strchrnul.h
__strchrnul
char * __strchrnul(const char *s, int c)
Definition:
strchrnul.c:13
src
string
strchrnul.c
Generated by
1.8.15