fix config file path
[AROS.git] / compiler / clib / strrchr.c
blob9c51ff8b4ae31725a859796ae6339c8d11a5ff64
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function strrchr().
6 */
8 #include <aros/macros.h>
9 #include <stdio.h>
11 /*****************************************************************************
13 NAME */
14 #include <string.h>
16 char * strrchr (
18 /* SYNOPSIS */
19 const char * str,
20 int c)
22 /* FUNCTION
23 Searches for the last character c in a string.
25 INPUTS
26 str - Search this string
27 c - Look for this character
29 RESULT
30 A pointer to the first occurence of c in str or NULL if c is not
31 found in str.
33 NOTES
35 EXAMPLE
36 char buffer[64];
38 strcpy (buffer, "Hello ");
40 // This returns a pointer to the second l in buffer.
41 strrchr (buffer, 'l');
43 // This returns NULL
44 strrchr (buffer, 'x');
46 BUGS
48 SEE ALSO
49 strrchr()
51 INTERNALS
52 It might seem that the algorithm below is slower than one which
53 first finds the end and then walks backwards but that would mean
54 to process some characters twice - if the string doesn't contain
55 c, it would mean to process every character twice.
57 ******************************************************************************/
59 char * p = NULL;
61 while (*str)
63 /* those casts are needed to compare chars > 127 */
64 if ((unsigned char)*str == (unsigned char)c)
65 p = (char *)str;
67 str ++;
70 return p;
71 } /* strrchr */
73 AROS_MAKE_ALIAS(strrchr, rindex);