1*47940Sbostic /*-
2*47940Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic * All rights reserved.
4*47940Sbostic *
5*47940Sbostic * %sccs.include.proprietary.c%
6*47940Sbostic */
7*47940Sbostic
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)rindex_.c 5.3 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic
122572Sdlw /*
132572Sdlw * find last occurrence of substring in string
142572Sdlw *
152572Sdlw * calling sequence:
162572Sdlw * character*(*) substr, string
172572Sdlw * indx = rindex (string, substr)
182572Sdlw * where:
192572Sdlw * indx will be the index of the first character of the last occurence
202572Sdlw * of substr in string, or zero if not found.
212572Sdlw */
222572Sdlw
rindex_(str,substr,slen,sublen)232572Sdlw long rindex_(str, substr, slen, sublen)
242572Sdlw char *str, *substr; long slen, sublen;
252572Sdlw {
2617230Sdlw register char *p = str + (slen - sublen);
2717230Sdlw register char *p1, *p2;
2817230Sdlw register int len;
292572Sdlw
3017230Sdlw if (sublen == 0)
3117230Sdlw return(0L);
3217230Sdlw while (p >= str) {
3317230Sdlw p1 = p;
3417230Sdlw p2 = substr;
3517230Sdlw len = sublen;
3617230Sdlw while ( *p1++ == *p2++ && --len > 0) ;
3717230Sdlw if ( len <= 0 )
382572Sdlw return((long)(++p - str));
3917230Sdlw p--;
4017230Sdlw }
412572Sdlw return(0L);
422572Sdlw }
43