os/ossrv/genericopenlibs/cstdlib/LCHAR/STRRCHR.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * FUNCTION
    16 * <<strrchr>>---reverse search for character in string
    17 * INDEX
    18 * strrchr
    19 * ANSI_SYNOPSIS
    20 * #include <string.h>
    21 * char * strrchr(const char *<[string]>, int <[c]>);
    22 * TRAD_SYNOPSIS
    23 * #include <string.h>
    24 * char * strrchr(<[string]>, <[c]>);
    25 * char *<[string]>;
    26 * int *<[c]>;
    27 * This function finds the last occurence of <[c]> (converted to
    28 * a char) in the string pointed to by <[string]> (including the
    29 * terminating null character).
    30 * RETURNS
    31 * Returns a pointer to the located character, or a null pointer
    32 * if <[c]> does not occur in <[string]>.
    33 * PORTABILITY
    34 * <<strrchr>> is ANSI C.
    35 * <<strrchr>> requires no supporting OS subroutines.
    36 * QUICKREF
    37 * strrchr ansi pure
    38 * 
    39 *
    40 */
    41 
    42 
    43 
    44 #include <string.h>
    45 
    46 /**
    47 Find last occurrence of character in string.
    48 Returns the last occurrence of c in string.
    49 The null-terminating character is included as part of the string and can also be searched.
    50 @return If character is found, a pointer to the last occurrence of c in string is returned.
    51 If not, NULL is returned.
    52 @param s Null-terminated string scanned in the search. 
    53 @param i Character to be found.
    54 */
    55 EXPORT_C char *
    56 strrchr (const char *s, int i)
    57 {
    58 	const char *last = NULL;
    59 	i = (char)i;
    60 
    61 	for (;;)
    62 	{
    63 		int c = *s++;
    64 		if (c == i)
    65 			last = s - 1;
    66 		if (c == 0)
    67 			break;
    68 	}
    69 
    70   return (char *) last;
    71 }
    72 
    73 EXPORT_C char *
    74 rindex (const char *s, int c)
    75 {
    76   return strrchr (s, c);
    77 }