1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRRCHR.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,77 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* FUNCTION
1.19 +* <<strrchr>>---reverse search for character in string
1.20 +* INDEX
1.21 +* strrchr
1.22 +* ANSI_SYNOPSIS
1.23 +* #include <string.h>
1.24 +* char * strrchr(const char *<[string]>, int <[c]>);
1.25 +* TRAD_SYNOPSIS
1.26 +* #include <string.h>
1.27 +* char * strrchr(<[string]>, <[c]>);
1.28 +* char *<[string]>;
1.29 +* int *<[c]>;
1.30 +* This function finds the last occurence of <[c]> (converted to
1.31 +* a char) in the string pointed to by <[string]> (including the
1.32 +* terminating null character).
1.33 +* RETURNS
1.34 +* Returns a pointer to the located character, or a null pointer
1.35 +* if <[c]> does not occur in <[string]>.
1.36 +* PORTABILITY
1.37 +* <<strrchr>> is ANSI C.
1.38 +* <<strrchr>> requires no supporting OS subroutines.
1.39 +* QUICKREF
1.40 +* strrchr ansi pure
1.41 +*
1.42 +*
1.43 +*/
1.44 +
1.45 +
1.46 +
1.47 +#include <string.h>
1.48 +
1.49 +/**
1.50 +Find last occurrence of character in string.
1.51 +Returns the last occurrence of c in string.
1.52 +The null-terminating character is included as part of the string and can also be searched.
1.53 +@return If character is found, a pointer to the last occurrence of c in string is returned.
1.54 +If not, NULL is returned.
1.55 +@param s Null-terminated string scanned in the search.
1.56 +@param i Character to be found.
1.57 +*/
1.58 +EXPORT_C char *
1.59 +strrchr (const char *s, int i)
1.60 +{
1.61 + const char *last = NULL;
1.62 + i = (char)i;
1.63 +
1.64 + for (;;)
1.65 + {
1.66 + int c = *s++;
1.67 + if (c == i)
1.68 + last = s - 1;
1.69 + if (c == 0)
1.70 + break;
1.71 + }
1.72 +
1.73 + return (char *) last;
1.74 +}
1.75 +
1.76 +EXPORT_C char *
1.77 +rindex (const char *s, int c)
1.78 +{
1.79 + return strrchr (s, c);
1.80 +}