Reactos
at master 78 lines 2.3 kB view raw
1/*** 2*strcoll.c - Collate locale strings 3* 4* Copyright (c) Microsoft Corporation. All rights reserved. 5* 6*Purpose: 7* Compare two strings using the locale LC_COLLATE information. 8* 9*******************************************************************************/ 10#include <corecrt_internal.h> 11#include <ctype.h> 12#include <locale.h> 13#include <string.h> 14 15/*** 16*int strcoll() - Collate locale strings 17* 18*Purpose: 19* Compare two strings using the locale LC_COLLATE information. 20* [ANSI]. 21* 22* Non-C locale support available under _INTL switch. 23* In the C locale, strcoll() simply resolves to strcmp(). 24*Entry: 25* const char *s1 = pointer to the first string 26* const char *s2 = pointer to the second string 27* 28*Exit: 29* Less than 0 = first string less than second string 30* 0 = strings are equal 31* Greater than 0 = first string greater than second string 32* Returns _NLSCMPERROR is something went wrong 33* 34*Exceptions: 35* Input parameters are validated. Refer to the validation section of the function. 36* 37*******************************************************************************/ 38 39extern "C" int __cdecl _strcoll_l ( 40 const char *_string1, 41 const char *_string2, 42 _locale_t plocinfo 43 ) 44{ 45 int ret; 46 _LocaleUpdate _loc_update(plocinfo); 47 48 /* validation section */ 49 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR); 50 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR); 51 52 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr ) 53 return strcmp(_string1, _string2); 54 55 if ( 0 == (ret = __acrt_CompareStringA( 56 _loc_update.GetLocaleT(), _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE], 57 SORT_STRINGSORT, 58 _string1, 59 -1, 60 _string2, 61 -1, 62 _loc_update.GetLocaleT()->locinfo->lc_collate_cp )) ) 63 { 64 errno = EINVAL; 65 return _NLSCMPERROR; 66 } 67 68 return (ret - 2); 69 70} 71 72extern "C" int __cdecl strcoll ( 73 const char *_string1, 74 const char *_string2 75 ) 76{ 77 return _strcoll_l(_string1, _string2, nullptr); 78}