nckernel  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
memcmp.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <string.h>
4 
5 int memcmp(void *dest, void *src, size_t size)
6 {
7  register unsigned long * __restrict__ word_dest;
8  register unsigned long * __restrict__ word_src;
9  register unsigned char * __restrict__ byte_dest;
10  register unsigned char * __restrict__ byte_src;
11 
12  word_dest = dest;
13  word_src = src;
14  while (size > sizeof(*word_dest)) {
15  if (*word_dest != *word_src) {
16  return (int)(*word_dest - *word_src);
17  }
18  word_dest++;
19  word_src++;
20  size -= sizeof(*word_dest);
21  }
22 
23  byte_dest = (unsigned char*)word_dest;
24  byte_src = (unsigned char*)word_src;
25  while (size-- > 0) {
26  if (*byte_dest != *byte_src) {
27  return (int)(*byte_dest - *byte_src);
28  }
29  byte_dest++;
30  byte_src++;
31  }
32 
33  return 0;
34 }
35 
36 /* End of a file */