1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRCMP.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,92 @@
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 +* <<strcmp>>---character string compare
1.20 +* INDEX
1.21 +* strcmp
1.22 +* ANSI_SYNOPSIS
1.23 +* #include <string.h>
1.24 +* int strcmp(const char *<[a]>, const char *<[b]>);
1.25 +* TRAD_SYNOPSIS
1.26 +* #include <string.h>
1.27 +* int strcmp(<[a]>, <[b]>)
1.28 +* char *<[a]>;
1.29 +* char *<[b]>;
1.30 +* <<strcmp>> compares the string at <[a]> to
1.31 +* the string at <[b]>.
1.32 +* RETURNS
1.33 +* If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
1.34 +* <<strcmp>> returns a number greater than zero. If the two
1.35 +* strings match, <<strcmp>> returns zero. If <<*<[a]>>>
1.36 +* sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a
1.37 +* number less than zero.
1.38 +* PORTABILITY
1.39 +* <<strcmp>> is ANSI C.
1.40 +* <<strcmp>> requires no supporting OS subroutines.
1.41 +* QUICKREF
1.42 +* strcmp ansi pure
1.43 +*
1.44 +*
1.45 +*/
1.46 +
1.47 +
1.48 +
1.49 +#include <string.h>
1.50 +
1.51 +/**
1.52 +Compare two strings.
1.53 +Compares string1 to s1 character by character.
1.54 +This function starts comparing the first character of each string.
1.55 +If they are equal to each other continues with the following pair
1.56 +until the characters differ or until end of string is reached.
1.57 +@return a value indicating the lexicographical relation between the strings
1.58 +@param s1 Null-terminated string to compare.
1.59 +@param s2 Null-terminated string to compare.
1.60 +*/
1.61 +EXPORT_C int
1.62 +strcmp (const char *s1, const char *s2)
1.63 +{
1.64 + const unsigned char* p1=(const unsigned char*)s1;
1.65 + const unsigned char* p2=(const unsigned char*)s2;
1.66 + for (;;)
1.67 + {
1.68 + int c1=*p1++;
1.69 + int d=c1-*p2++;
1.70 + if (d!=0)
1.71 + return d;
1.72 + if (c1==0)
1.73 + return d;
1.74 + }
1.75 +}
1.76 +
1.77 +/**
1.78 +Compare the wide-character string pointed to by s1 to the wide-character
1.79 +string pointed to by s2.
1.80 +@return an integer greater than, equal to, or less than zero, if the
1.81 +wide-character string pointed to by s1 is greater than, equal to,
1.82 +or less than the wide-character string pointed to by s2.
1.83 +*/
1.84 +EXPORT_C int wcscmp (const wchar_t *s1, const wchar_t *s2)
1.85 +{
1.86 + for (;;)
1.87 + {
1.88 + int c1=*s1++;
1.89 + int d=c1-*s2++;
1.90 + if (d!=0)
1.91 + return d;
1.92 + if (c1==0)
1.93 + return d;
1.94 + }
1.95 +}