xref: /inferno-os/lib9/utfrrune.c (revision ab545a4ce0f664cdb3c344770912616856dece27)
1 #include "lib9.h"
2 
3 char*
utfrrune(char * s,long c)4 utfrrune(char *s, long c)
5 {
6 	long c1;
7 	Rune r;
8 	char *s1;
9 
10 	if(c < Runesync)		/* not part of utf sequence */
11 		return strrchr(s, c);
12 
13 	s1 = 0;
14 	for(;;) {
15 		c1 = *(uchar*)s;
16 		if(c1 < Runeself) {	/* one byte rune */
17 			if(c1 == 0)
18 				return s1;
19 			if(c1 == c)
20 				s1 = s;
21 			s++;
22 			continue;
23 		}
24 		c1 = chartorune(&r, s);
25 		if(r == c)
26 			s1 = s;
27 		s += c1;
28 	}
29 }
30