Indentation fix, cleanup.
[AROS.git] / compiler / stdc / strrchr.c
blobfc04bef5b001c1f80302be8f4481f4edc1db3f1b
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function strrchr().
6 */
8 #include <aros/macros.h>
10 /*****************************************************************************
12 NAME */
13 #include <string.h>
15 char * strrchr (
17 /* SYNOPSIS */
18 const char * str,
19 int c)
21 /* FUNCTION
22 Searches for the last character c in a string.
24 INPUTS
25 str - Search this string
26 c - Look for this character
28 RESULT
29 A pointer to the first occurence of c in str or NULL if c is not
30 found in str.
32 NOTES
34 EXAMPLE
35 char buffer[64];
37 strcpy (buffer, "Hello ");
39 // This returns a pointer to the second l in buffer.
40 strrchr (buffer, 'l');
42 // This returns NULL
43 strrchr (buffer, 'x');
45 BUGS
47 SEE ALSO
48 strrchr()
50 INTERNALS
51 It might seem that the algorithm below is slower than one which
52 first finds the end and then walks backwards but that would mean
53 to process some characters twice - if the string doesn't contain
54 c, it would mean to process every character twice.
56 ******************************************************************************/
58 char * p = NULL;
60 while (*str)
62 /* those casts are needed to compare chars > 127 */
63 if ((unsigned char)*str == (unsigned char)c)
64 p = (char *)str;
66 str ++;
69 return p;
70 } /* strrchr */