9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

cistrncmp.c (366B)


      1 #include <u.h>
      2 #include <libc.h>
      3 
      4 int
      5 cistrncmp(char *s1, char *s2, int n)
      6 {
      7 	int c1, c2;
      8 
      9 	while(*s1 && n-- > 0){
     10 		c1 = *(uchar*)s1++;
     11 		c2 = *(uchar*)s2++;
     12 
     13 		if(c1 == c2)
     14 			continue;
     15 
     16 		if(c1 >= 'A' && c1 <= 'Z')
     17 			c1 -= 'A' - 'a';
     18 
     19 		if(c2 >= 'A' && c2 <= 'Z')
     20 			c2 -= 'A' - 'a';
     21 
     22 		if(c1 != c2)
     23 			return c1 - c2;
     24 	}
     25 	if(n <= 0)
     26 		return 0;
     27 	return -*s2;
     28 }