summaryrefslogtreecommitdiff
path: root/missing/memcmp.c
blob: 9657e6c372234a86c8e9fe3d14f6df74e47eebed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* public domain rewrite of memcmp(3) */

#include "ruby/missing.h"
#include <stddef.h>

int
memcmp(const void *s1, const void *s2, size_t len)
{
    register unsigned char *a = (unsigned char*)s1;
    register unsigned char *b = (unsigned char*)s2;
    register int tmp;

    for (; len; --len) {
	tmp = *a++ - *b++;
	if (tmp)
	    return tmp;
    }
    return 0;
}