Changeset 2353


Ignore:
Timestamp:
Jul 14, 2011, 4:05:00 AM (4 years ago)
Author:
quozl
Message:

memcmp version from multicast-nand moved into library, Mitch identified
it as better than the one that was there.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • clients/lib/mem.c

    r2343 r2353  
    1818
    1919int
    20 memcmp(void *s1, void *s2, int len)
     20memcmp(const void *s1, const void *s2, size_t n)
    2121{
    22         for (; len--; ++s1, ++s2)
    23                 if (*(unsigned char *)s1 != *(unsigned char *)s2)
    24                         return *(unsigned char *)s1 - *(unsigned char *)s2;
     22        int diff;
     23        while (n--) {
     24                diff = *(unsigned char *)s1++ - *(unsigned char *)s2++;
     25                if (diff)
     26                        return (diff < 0) ? -1 : 1;
     27        }
    2528        return 0;
    2629}
Note: See TracChangeset for help on using the changeset viewer.