Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
memcmp.c File Reference
#include <string.h>
Include dependency graph for memcmp.c:

Go to the source code of this file.

Functions

int __attribute__ ((weak))
 

Function Documentation

◆ __attribute__()

int __attribute__ ( (weak)  )

p1 and p2 are the same memory? easy peasy! bail out

Definition at line 3 of file memcmp.c.

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 }