diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-05-10 16:31:20 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-05-13 08:33:39 +0200 |
commit | 250170d3b03d8e1f56e66c901abb096d8cc80cf4 (patch) | |
tree | 520a91e117251c1137624ccf6275f5617b48c5c7 | |
parent | acbd162f8859c8172f2b61a678e36993121a44da (diff) |
Move OPENSSL_strcasecmp() and related to o_str.c
Otherwise the implementation is unnecessarily duplicated in legacy.so.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18293)
-rw-r--r-- | crypto/ctype.c | 87 | ||||
-rw-r--r-- | crypto/o_str.c | 65 | ||||
-rw-r--r-- | include/crypto/ctype.h | 3 | ||||
-rw-r--r-- | include/internal/cryptlib.h | 2 |
4 files changed, 68 insertions, 89 deletions
diff --git a/crypto/ctype.c b/crypto/ctype.c index b332074da5..2165213889 100644 --- a/crypto/ctype.c +++ b/crypto/ctype.c @@ -7,20 +7,11 @@ * https://www.openssl.org/source/license.html */ -#include "e_os.h" #include <string.h> #include <stdio.h> #include "crypto/ctype.h" #include <openssl/ebcdic.h> -#include <openssl/crypto.h> -#include "internal/core.h" -#include "internal/thread_once.h" -#ifndef OPENSSL_NO_LOCALE -# include <locale.h> -# ifdef OPENSSL_SYS_MACOSX -# include <xlocale.h> -# endif -#endif + /* * Define the character classes for each character in the seven bit ASCII * character set. This is independent of the host's character set, characters @@ -287,79 +278,3 @@ int ossl_ascii_isdigit(const char inchar) { return 1; return 0; } - -#ifndef OPENSSL_NO_LOCALE -# ifndef FIPS_MODULE -static locale_t loc; - -static int locale_base_inited = 0; -static CRYPTO_ONCE locale_base = CRYPTO_ONCE_STATIC_INIT; -static CRYPTO_ONCE locale_base_deinit = CRYPTO_ONCE_STATIC_INIT; - -void *ossl_c_locale() { - return (void *)loc; -} - -DEFINE_RUN_ONCE_STATIC(ossl_init_locale_base) -{ -# ifdef OPENSSL_SYS_WINDOWS - loc = _create_locale(LC_COLLATE, "C"); -# else - loc = newlocale(LC_COLLATE_MASK, "C", (locale_t) 0); -# endif - locale_base_inited = 1; - return (loc == (locale_t) 0) ? 0 : 1; -} - -DEFINE_RUN_ONCE_STATIC(ossl_deinit_locale_base) -{ - if (locale_base_inited && loc) { - freelocale(loc); - loc = NULL; - } - return 1; -} - -int ossl_init_casecmp() -{ - return RUN_ONCE(&locale_base, ossl_init_locale_base); -} - -void ossl_deinit_casecmp() { - (void)RUN_ONCE(&locale_base_deinit, ossl_deinit_locale_base); -} -# 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() { - 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 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 <string.h> #include <limits.h> +#ifndef OPENSSL_NO_LOCALE +# include <locale.h> +# ifdef OPENSSL_SYS_MACOSX +# include <xlocale.h> +# endif +#endif #include <openssl/crypto.h> #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 diff --git a/include/crypto/ctype.h b/include/crypto/ctype.h index 16f135df3b..6deee3b947 100644 --- a/include/crypto/ctype.h +++ b/include/crypto/ctype.h @@ -79,7 +79,4 @@ int ossl_ascii_isdigit(const char inchar); # define ossl_isxdigit(c) (ossl_ctype_check((c), CTYPE_MASK_xdigit)) # define ossl_isbase64(c) (ossl_ctype_check((c), CTYPE_MASK_base64)) # define ossl_isasn1print(c) (ossl_ctype_check((c), CTYPE_MASK_asn1print)) - -int ossl_init_casecmp(void); -void ossl_deinit_casecmp(void); #endif diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h index 1291299b6e..640b41cc10 100644 --- a/include/internal/cryptlib.h +++ b/include/internal/cryptlib.h @@ -258,4 +258,6 @@ static ossl_inline int ossl_is_absolute_path(const char *path) return path[0] == '/'; } +int ossl_init_casecmp_int(void); +void ossl_deinit_casecmp(void); #endif |