genericopenlibs/cstdlib/LCHAR/STRCMP.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 * <<strcmp>>---character string compare
       
    17 * INDEX
       
    18 * strcmp
       
    19 * ANSI_SYNOPSIS
       
    20 * #include <string.h>
       
    21 * int strcmp(const char *<[a]>, const char *<[b]>);
       
    22 * TRAD_SYNOPSIS
       
    23 * #include <string.h>
       
    24 * int strcmp(<[a]>, <[b]>)
       
    25 * char *<[a]>;
       
    26 * char *<[b]>;
       
    27 * <<strcmp>> compares the string at <[a]> to
       
    28 * the string at <[b]>.
       
    29 * RETURNS
       
    30 * If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
       
    31 * <<strcmp>> returns a number greater than zero.  If the two
       
    32 * strings match, <<strcmp>> returns zero.  If <<*<[a]>>>
       
    33 * sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a
       
    34 * number less than zero.
       
    35 * PORTABILITY
       
    36 * <<strcmp>> is ANSI C.
       
    37 * <<strcmp>> requires no supporting OS subroutines.
       
    38 * QUICKREF
       
    39 * strcmp ansi pure
       
    40 * 
       
    41 *
       
    42 */
       
    43 
       
    44 
       
    45 
       
    46 #include <string.h>
       
    47 
       
    48 /**
       
    49 Compare two strings.
       
    50 Compares string1 to s1 character by character.
       
    51 This function starts comparing the first character of each string.
       
    52 If they are equal to each other continues with the following pair
       
    53 until the characters differ or until end of string is reached.
       
    54 @return a value indicating the lexicographical relation between the strings
       
    55 @param s1 Null-terminated string to compare. 
       
    56 @param s2 Null-terminated string to compare.
       
    57 */
       
    58 EXPORT_C int
       
    59 strcmp (const char *s1, const char *s2)
       
    60 {
       
    61 	const unsigned char* p1=(const unsigned char*)s1;
       
    62 	const unsigned char* p2=(const unsigned char*)s2;
       
    63 	for (;;)
       
    64 	{
       
    65 		int c1=*p1++;
       
    66 		int d=c1-*p2++;
       
    67 		if (d!=0)
       
    68 			return d;
       
    69 		if (c1==0)
       
    70 			return d;
       
    71 	}
       
    72 }
       
    73 
       
    74 /**
       
    75 Compare the wide-character string pointed to by s1 to the wide-character
       
    76 string pointed to by s2.
       
    77 @return an integer greater than, equal to, or  less than zero, if the 
       
    78 wide-character string pointed to by s1 is greater than, equal to,  
       
    79 or less than the wide-character string pointed to by s2.
       
    80 */
       
    81 EXPORT_C int wcscmp (const wchar_t *s1, const wchar_t *s2)
       
    82 {
       
    83 	for (;;)
       
    84 	{
       
    85 		int c1=*s1++;
       
    86 		int d=c1-*s2++;
       
    87 		if (d!=0)
       
    88 			return d;
       
    89 		if (c1==0)
       
    90 			return d;
       
    91 	}
       
    92 }