Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUNCTION |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 3 | <<strrchr>>---reverse search for character in string |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 4 | |
| 5 | INDEX |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 6 | strrchr |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 7 | |
| 8 | ANSI_SYNOPSIS |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 9 | #include <string.h> |
| 10 | char * strrchr(const char *<[string]>, int <[c]>); |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 11 | |
| 12 | TRAD_SYNOPSIS |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 13 | #include <string.h> |
| 14 | char * strrchr(<[string]>, <[c]>); |
| 15 | char *<[string]>; |
| 16 | int *<[c]>; |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 17 | |
| 18 | DESCRIPTION |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 19 | 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 Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 22 | |
| 23 | RETURNS |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 24 | Returns a pointer to the located character, or a null pointer |
| 25 | if <[c]> does not occur in <[string]>. |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 26 | |
| 27 | PORTABILITY |
| 28 | <<strrchr>> is ANSI C. |
| 29 | |
| 30 | <<strrchr>> requires no supporting OS subroutines. |
| 31 | |
| 32 | QUICKREF |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 33 | strrchr ansi pure |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #include <string.h> |
Thomas Martitz | f32bd59 | 2010-06-22 18:34:03 +0000 | [diff] [blame] | 37 | #include "_ansi.h" /* for _DEFUN */ |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 38 | |
| 39 | char * |
| 40 | _DEFUN (strrchr, (s, i), |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 41 | _CONST char *s _AND |
| 42 | int i) |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 43 | { |
| 44 | _CONST char *last = NULL; |
| 45 | |
| 46 | if (i) |
| 47 | { |
| 48 | while ((s=strchr(s, i))) |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 49 | { |
| 50 | last = s; |
| 51 | s++; |
| 52 | } |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 53 | } |
| 54 | else |
| 55 | { |
| 56 | last = strchr(s, i); |
| 57 | } |
Andree Buschmann | 0b7dcd6 | 2010-02-22 21:24:09 +0000 | [diff] [blame] | 58 | |
Björn Stenberg | b69338f | 2002-05-30 21:03:17 +0000 | [diff] [blame] | 59 | return (char *) last; |
| 60 | } |