blob: 0489edd499d0b0f35d228878a5a165fee0e4ef2d [file] [log] [blame]
Björn Stenbergb69338f2002-05-30 21:03:17 +00001/*
2FUNCTION
Andree Buschmann0b7dcd62010-02-22 21:24:09 +00003 <<strrchr>>---reverse search for character in string
Björn Stenbergb69338f2002-05-30 21:03:17 +00004
5INDEX
Andree Buschmann0b7dcd62010-02-22 21:24:09 +00006 strrchr
Björn Stenbergb69338f2002-05-30 21:03:17 +00007
8ANSI_SYNOPSIS
Andree Buschmann0b7dcd62010-02-22 21:24:09 +00009 #include <string.h>
10 char * strrchr(const char *<[string]>, int <[c]>);
Björn Stenbergb69338f2002-05-30 21:03:17 +000011
12TRAD_SYNOPSIS
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000013 #include <string.h>
14 char * strrchr(<[string]>, <[c]>);
15 char *<[string]>;
16 int *<[c]>;
Björn Stenbergb69338f2002-05-30 21:03:17 +000017
18DESCRIPTION
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000019 This function finds the last occurence of <[c]> (converted to
20 a char) in the string pointed to by <[string]> (including the
21 terminating null character).
Björn Stenbergb69338f2002-05-30 21:03:17 +000022
23RETURNS
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000024 Returns a pointer to the located character, or a null pointer
25 if <[c]> does not occur in <[string]>.
Björn Stenbergb69338f2002-05-30 21:03:17 +000026
27PORTABILITY
28<<strrchr>> is ANSI C.
29
30<<strrchr>> requires no supporting OS subroutines.
31
32QUICKREF
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000033 strrchr ansi pure
Björn Stenbergb69338f2002-05-30 21:03:17 +000034*/
35
36#include <string.h>
Thomas Martitzf32bd592010-06-22 18:34:03 +000037#include "_ansi.h" /* for _DEFUN */
Björn Stenbergb69338f2002-05-30 21:03:17 +000038
39char *
40_DEFUN (strrchr, (s, i),
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000041 _CONST char *s _AND
42 int i)
Björn Stenbergb69338f2002-05-30 21:03:17 +000043{
44 _CONST char *last = NULL;
45
46 if (i)
47 {
48 while ((s=strchr(s, i)))
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000049 {
50 last = s;
51 s++;
52 }
Björn Stenbergb69338f2002-05-30 21:03:17 +000053 }
54 else
55 {
56 last = strchr(s, i);
57 }
Andree Buschmann0b7dcd62010-02-22 21:24:09 +000058
Björn Stenbergb69338f2002-05-30 21:03:17 +000059 return (char *) last;
60}