1 /*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)rindex_.c 5.3 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 /*
13 * find last occurrence of substring in string
14 *
15 * calling sequence:
16 * character*(*) substr, string
17 * indx = rindex (string, substr)
18 * where:
19 * indx will be the index of the first character of the last occurence
20 * of substr in string, or zero if not found.
21 */
22
rindex_(str,substr,slen,sublen)23 long rindex_(str, substr, slen, sublen)
24 char *str, *substr; long slen, sublen;
25 {
26 register char *p = str + (slen - sublen);
27 register char *p1, *p2;
28 register int len;
29
30 if (sublen == 0)
31 return(0L);
32 while (p >= str) {
33 p1 = p;
34 p2 = substr;
35 len = sublen;
36 while ( *p1++ == *p2++ && --len > 0) ;
37 if ( len <= 0 )
38 return((long)(++p - str));
39 p--;
40 }
41 return(0L);
42 }
43