forked from totalspectrum/spin2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemcmp.c
More file actions
36 lines (30 loc) · 718 Bytes
/
Copy pathmemcmp.c
File metadata and controls
36 lines (30 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* from Henry Spencer's stringlib */
#include <stddef.h>
#include <string.h>
/*
* memcmp - compare bytes
*
* CHARBITS should be defined only if the compiler lacks "unsigned char".
* It should be a mask, e.g. 0377 for an 8-bit machine.
*/
#ifndef CHARBITS
# define UNSCHAR(c) ((unsigned char)(c))
#else
# define UNSCHAR(c) ((c)&CHARBITS)
#endif
int /* <0, == 0, >0 */
memcmp(const void *s1, const void *s2, size_t size)
{
register const char *scan1;
register const char *scan2;
register size_t n;
scan1 = (const char *) s1;
scan2 = (const char *) s2;
for (n = size; n > 0; n--)
if (*scan1 == *scan2) {
scan1++;
scan2++;
} else
return(UNSCHAR (*scan1) - UNSCHAR (*scan2));
return(0);
}