From 250170d3b03d8e1f56e66c901abb096d8cc80cf4 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 10 May 2022 16:31:20 +0200 Subject: Move OPENSSL_strcasecmp() and related to o_str.c Otherwise the implementation is unnecessarily duplicated in legacy.so. Reviewed-by: Dmitry Belyavskiy Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/18293) --- crypto/o_str.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'crypto/o_str.c') diff --git a/crypto/o_str.c b/crypto/o_str.c index 5c4e4e7781..30e5820c49 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -8,9 +8,17 @@ */ #include "e_os.h" +#include #include +#ifndef OPENSSL_NO_LOCALE +# include +# ifdef OPENSSL_SYS_MACOSX +# include +# endif +#endif #include #include "internal/cryptlib.h" +#include "internal/core.h" #define DEFAULT_SEPARATOR ':' #define CH_ZERO '\0' @@ -338,3 +346,60 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen) return 1; #endif } + +#ifndef OPENSSL_NO_LOCALE +# ifndef FIPS_MODULE +static locale_t loc; + + +void *ossl_c_locale() { + return (void *)loc; +} + +int ossl_init_casecmp_int() { +# ifdef OPENSSL_SYS_WINDOWS + loc = _create_locale(LC_COLLATE, "C"); +# else + loc = newlocale(LC_COLLATE_MASK, "C", (locale_t) 0); +# endif + return (loc == (locale_t) 0) ? 0 : 1; +} + +void ossl_deinit_casecmp() { + freelocale(loc); +} +# endif + +int OPENSSL_strcasecmp(const char *s1, const char *s2) +{ + return strcasecmp_l(s1, s2, (locale_t)ossl_c_locale()); +} + +int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n) +{ + return strncasecmp_l(s1, s2, n, (locale_t)ossl_c_locale()); +} +#else +# ifndef FIPS_MODULE +void *ossl_c_locale() { + return NULL; +} +# endif + +int ossl_init_casecmp_int() { + return 1; +} + +void ossl_deinit_casecmp() { +} + +int OPENSSL_strcasecmp(const char *s1, const char *s2) +{ + return strcasecmp(s1, s2); +} + +int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n) +{ + return strncasecmp(s1, s2, n); +} +#endif -- cgit v1.2.3