summaryrefslogtreecommitdiff
path: root/firmware/libc/strrchr.c
blob: 0489edd499d0b0f35d228878a5a165fee0e4ef2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
FUNCTION
        <<strrchr>>---reverse search for character in string

INDEX
        strrchr

ANSI_SYNOPSIS
        #include <string.h>
        char * strrchr(const char *<[string]>, int <[c]>);

TRAD_SYNOPSIS
        #include <string.h>
        char * strrchr(<[string]>, <[c]>);
        char *<[string]>;
        int *<[c]>;

DESCRIPTION
        This function finds the last occurence of <[c]> (converted to
        a char) in the string pointed to by <[string]> (including the
        terminating null character).

RETURNS
        Returns a pointer to the located character, or a null pointer
        if <[c]> does not occur in <[string]>.

PORTABILITY
<<strrchr>> is ANSI C.

<<strrchr>> requires no supporting OS subroutines.

QUICKREF
        strrchr ansi pure
*/

#include <string.h>
#include "_ansi.h" /* for _DEFUN */

char *
_DEFUN (strrchr, (s, i),
        _CONST char *s _AND
        int i)
{
  _CONST char *last = NULL;

  if (i)
    {
      while ((s=strchr(s, i)))
        {
          last = s;
          s++;
        }
    }
  else
    {
      last = strchr(s, i);
    }
                  
  return (char *) last;
}