1 /*
2 FUNCTION
3 <<strrchr>>---reverse search for character in string
4
5 INDEX
6 strrchr
7
8 SYNOPSIS
9 #include <string.h>
10 char * strrchr(const char *<[string]>, int <[c]>);
11
12 DESCRIPTION
13 This function finds the last occurence of <[c]> (converted to
14 a char) in the string pointed to by <[string]> (including the
15 terminating null character).
16
17 RETURNS
18 Returns a pointer to the located character, or a null pointer
19 if <[c]> does not occur in <[string]>.
20
21 PORTABILITY
22 <<strrchr>> is ANSI C.
23
24 <<strrchr>> requires no supporting OS subroutines.
25
26 QUICKREF
27 strrchr ansi pure
28 */
29
30 #include <string.h>
31
32 char *
strrchr(const char * s,int i)33 strrchr (const char *s,
34 int i)
35 {
36 const char *last = NULL;
37
38 if (i)
39 {
40 while ((s=strchr(s, i)))
41 {
42 last = s;
43 s++;
44 }
45 }
46 else
47 {
48 last = strchr(s, i);
49 }
50
51 return (char *) last;
52 }
53