ReactOS 0.4.16-dev-889-g9563c07
stricmp.cpp
Go to the documentation of this file.
1/***
2*stricmp.cpp - contains case-insensitive string comp routine _stricmp
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* contains _stricmp()
8*
9*******************************************************************************/
10#include <corecrt_internal.h>
11#include <ctype.h>
12#include <locale.h>
13#include <string.h>
14
15#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 Prefast can't see that we are checking for terminal nul.
16
17/***
18*int _stricmp(lhs, rhs) - compare strings, ignore case
19*
20*Purpose:
21* _stricmp/_strcmpi perform a case-insensitive string comparision.
22* For differences, upper case letters are mapped to lower case.
23* Thus, "abc_" < "ABCD" since "_" < "d".
24*
25*Entry:
26* char *lhs, *rhs - strings to compare
27*
28*Return:
29* Returns <0 if lhs < rhs
30* Returns 0 if lhs = rhs
31* Returns >0 if lhs > rhs
32* Returns _NLSCMPERROR if 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 _stricmp_l (
40 char const * const lhs,
41 char const * const rhs,
43 )
44{
45 /* validation section */
46 _VALIDATE_RETURN(lhs != nullptr, EINVAL, _NLSCMPERROR);
47 _VALIDATE_RETURN(rhs != nullptr, EINVAL, _NLSCMPERROR);
48
49 unsigned char const * lhs_ptr = reinterpret_cast<unsigned char const *>(lhs);
50 unsigned char const * rhs_ptr = reinterpret_cast<unsigned char const *>(rhs);
51
52 _LocaleUpdate _loc_update(plocinfo);
53
54 int result;
55 int lhs_value;
56 int rhs_value;
57 do
58 {
59 lhs_value = _tolower_fast_internal(*lhs_ptr++, _loc_update.GetLocaleT());
60 rhs_value = _tolower_fast_internal(*rhs_ptr++, _loc_update.GetLocaleT());
61 result = lhs_value - rhs_value;
62 }
63 while (result == 0 && lhs_value != 0);
64
65 return result;
66}
67
68extern "C" int __cdecl __ascii_stricmp (
69 char const * const lhs,
70 char const * const rhs
71 )
72{
73 unsigned char const * lhs_ptr = reinterpret_cast<unsigned char const *>(lhs);
74 unsigned char const * rhs_ptr = reinterpret_cast<unsigned char const *>(rhs);
75
76 int result;
77 int lhs_value;
78 int rhs_value;
79 do
80 {
81 lhs_value = __ascii_tolower(*lhs_ptr++);
82 rhs_value = __ascii_tolower(*rhs_ptr++);
83 result = lhs_value - rhs_value;
84 }
85 while (result == 0 && lhs_value != 0);
86
87 return result;
88}
89
90extern "C" int __cdecl _stricmp (
91 char const * const lhs,
92 char const * const rhs
93 )
94{
95 if (!__acrt_locale_changed())
96 {
97 /* validation section */
98 _VALIDATE_RETURN(lhs != nullptr, EINVAL, _NLSCMPERROR);
99 _VALIDATE_RETURN(rhs != nullptr, EINVAL, _NLSCMPERROR);
100
101 return __ascii_stricmp(lhs, rhs);
102 }
103
104 return _stricmp_l(lhs, rhs, nullptr);
105}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define _stricmp
Definition: cat.c:22
_Check_return_ __forceinline unsigned char __cdecl _tolower_fast_internal(_In_ unsigned char const c, _In_ _locale_t const locale)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
GLuint64EXT * result
Definition: glext.h:11304
__forceinline int __CRTDECL __ascii_tolower(int const _C)
Definition: ctype.h:152
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define _NLSCMPERROR
Definition: string.h:19
int __cdecl __ascii_stricmp(char const *const lhs, char const *const rhs)
Definition: stricmp.cpp:68
int __cdecl _stricmp_l(char const *const lhs, char const *const rhs, _locale_t const plocinfo)
Definition: stricmp.cpp:39