3 <<memcmp>>---compare two memory areas
10 int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
13 This function compares not more than <[n]> characters of the
14 object pointed to by <[s1]> with the object pointed to by <[s2]>.
18 The function returns an integer greater than, equal to or
19 less than zero according to whether the object pointed to by
20 <[s1]> is greater than, equal to or less than the object
26 <<memcmp>> requires no supporting OS subroutines.
35 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
36 #define UNALIGNED(X, Y) \
37 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
39 /* How many bytes are copied each iteration of the word copy loop. */
40 #define LBLOCKSIZE (sizeof (long))
42 /* Threshhold for punting to the byte copier. */
43 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
46 memcmp (const void *m1
,
50 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
51 unsigned char *s1
= (unsigned char *) m1
;
52 unsigned char *s2
= (unsigned char *) m2
;
65 unsigned char *s1
= (unsigned char *) m1
;
66 unsigned char *s2
= (unsigned char *) m2
;
70 /* If the size is too small, or either pointer is unaligned,
71 then we punt to the byte compare loop. Hopefully this will
72 not turn up in inner loops. */
73 if (!TOO_SMALL(n
) && !UNALIGNED(s1
,s2
))
75 /* Otherwise, load and compare the blocks of memory one
77 a1
= (unsigned long*) s1
;
78 a2
= (unsigned long*) s2
;
79 while (n
>= LBLOCKSIZE
)
88 /* check m mod LBLOCKSIZE remaining characters */
90 s1
= (unsigned char*)a1
;
91 s2
= (unsigned char*)a2
;
103 #endif /* not PREFER_SIZE_OVER_SPEED */