1 /*
2 Copyright (c) 1994 Cygnus Support.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 at Cygnus Support, Inc.  Cygnus Support, Inc. may not be used to
11 endorse or promote products derived from this software without
12 specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 /*
18 FUNCTION
19 	<<strrchr>>---reverse search for character in string
20 
21 INDEX
22 	strrchr
23 
24 SYNOPSIS
25 	#include <string.h>
26 	char * strrchr(const char *<[string]>, int <[c]>);
27 
28 DESCRIPTION
29 	This function finds the last occurence of <[c]> (converted to
30 	a char) in the string pointed to by <[string]> (including the
31 	terminating null character).
32 
33 RETURNS
34 	Returns a pointer to the located character, or a null pointer
35 	if <[c]> does not occur in <[string]>.
36 
37 PORTABILITY
38 <<strrchr>> is ANSI C.
39 
40 <<strrchr>> requires no supporting OS subroutines.
41 
42 QUICKREF
43 	strrchr ansi pure
44 */
45 
46 #include <string.h>
47 
48 char *
strrchr(const char * s,int i)49 strrchr (const char *s,
50 	int i)
51 {
52   const char *last = NULL;
53   char c = i;
54 
55   if (c)
56     {
57       while ((s=strchr(s, c)))
58 	{
59 	  last = s;
60 	  s++;
61 	}
62     }
63   else
64     {
65       last = strchr(s, c);
66     }
67 
68   return (char *) last;
69 }
70