9base

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

cistrstr.c (357B)


      1 #include <u.h>
      2 #include <libc.h>
      3 
      4 char*
      5 cistrstr(char *s, char *sub)
      6 {
      7 	int c, csub, n;
      8 
      9 	csub = *sub;
     10 	if(csub == '\0')
     11 		return s;
     12 	if(csub >= 'A' && csub <= 'Z')
     13 		csub -= 'A' - 'a';
     14 	sub++;
     15 	n = strlen(sub);
     16 	for(; c = *s; s++){
     17 		if(c >= 'A' && c <= 'Z')
     18 			c -= 'A' - 'a';
     19 		if(c == csub && cistrncmp(s+1, sub, n) == 0)
     20 			return s;
     21 	}
     22 	return nil;
     23 }