3 <<memcmp>>---compare two memory areas
10 int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
14 int memcmp(<[s1]>, <[s2]>, <[n]>)
20 This function compares not more than <[n]> characters of the
21 object pointed to by <[s1]> with the object pointed to by <[s2]>.
25 The function returns an integer greater than, equal to or
26 less than zero according to whether the object pointed to by
27 <[s1]> is greater than, equal to or less than the object
33 <<memcmp>> requires no supporting OS subroutines.
42 /* Nonzero if either X or Y is not aligned on a "long" boundary. */
43 #define UNALIGNED(X, Y) \
44 (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
46 /* How many bytes are copied each iteration of the word copy loop. */
47 #define LBLOCKSIZE (sizeof (long))
49 /* Threshhold for punting to the byte copier. */
50 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
53 _DEFUN (memcmp
, (m1
, m2
, n
),
58 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
59 unsigned char *s1
= (unsigned char *) m1
;
60 unsigned char *s2
= (unsigned char *) m2
;
73 unsigned char *s1
= (unsigned char *) m1
;
74 unsigned char *s2
= (unsigned char *) m2
;
78 /* If the size is too small, or either pointer is unaligned,
79 then we punt to the byte compare loop. Hopefully this will
80 not turn up in inner loops. */
81 if (!TOO_SMALL(n
) && !UNALIGNED(s1
,s2
))
83 /* Otherwise, load and compare the blocks of memory one
85 a1
= (unsigned long*) s1
;
86 a2
= (unsigned long*) s2
;
87 while (n
>= LBLOCKSIZE
)
96 /* check m mod LBLOCKSIZE remaining characters */
111 #endif /* not PREFER_SIZE_OVER_SPEED */