Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
memcmp.c
Go to the documentation of this file.
1
#include <
string.h
>
2
3
int
__attribute__
((weak))
memcmp
(
const
void
* p1,
const
void
* p2,
size_t
n)
4
{
5
size_t
i;
6
10
if
(p1 == p2)
11
{
12
return
0;
13
}
14
15
if
(!p1)
16
{
17
return
1;
18
}
19
20
if
(!p2)
21
{
22
return
-1;
23
}
24
25
// This for loop does the comparing and pointer moving...
26
for
(i = 0; (i < n) && (*(
const
uint8_t*)p1 == *(
const
uint8_t*)p2);
27
i++, p1 = 1 + (
const
uint8_t*)p1, p2 = 1 + (
const
uint8_t*)p2)
28
{
29
// empty body
30
}
31
32
// if i == length, then we have passed the test
33
return
(i == n) ? 0 : (*(
const
uint8_t*)p1 - *(
const
uint8_t*)p2);
34
}
string.h
memcmp
int memcmp(const void *s1, const void *s2, size_t n)
Compares the first n characters of the two objects pointed to by s1 and s2.
__attribute__
int __attribute__((weak))
Definition:
memcmp.c:3
src
string
memcmp.c
Generated by
1.8.15