strcmp.c 221 B

1234567891011121314151617181920
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. strcmp(char *s1, char *s2)
  5. {
  6. unsigned c1, c2;
  7. for(;;) {
  8. c1 = *s1++;
  9. c2 = *s2++;
  10. if(c1 != c2) {
  11. if(c1 > c2)
  12. return 1;
  13. return -1;
  14. }
  15. if(c1 == 0)
  16. return 0;
  17. }
  18. }