memcmp.c 259 B

1234567891011121314151617181920212223
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. memcmp(void *a1, void *a2, ulong n)
  5. {
  6. uchar *s1, *s2;
  7. uint c1, c2;
  8. s1 = a1;
  9. s2 = a2;
  10. while(n > 0) {
  11. c1 = *s1++;
  12. c2 = *s2++;
  13. if(c1 != c2) {
  14. if(c1 > c2)
  15. return 1;
  16. return -1;
  17. }
  18. n--;
  19. }
  20. return 0;
  21. }