Move OPENSSL_strcasecmp() and related to o_str.c
authorTomas Mraz <tomas@openssl.org>
Tue, 10 May 2022 14:31:20 +0000 (16:31 +0200)
committerTomas Mraz <tomas@openssl.org>
Fri, 13 May 2022 06:30:41 +0000 (08:30 +0200)
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/18282)

crypto/ctype.c
crypto/o_str.c
include/crypto/ctype.h
include/internal/cryptlib.h

index dc930159170126587b7dd84913cd180bde60dfe7..2165213889f4ed34b44efbe23e23cd4b46261b25 100644 (file)
@@ -7,18 +7,11 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include "internal/e_os.h"
 #include <string.h>
 #include <stdio.h>
 #include "crypto/ctype.h"
 #include <openssl/ebcdic.h>
-#include "internal/core.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
@@ -285,60 +278,3 @@ int ossl_ascii_isdigit(const char inchar) {
         return 1;
     return 0;
 }
-
-#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
index 1ddb4493070ff28ae6a9d5e423de655b1df4c751..eccaa1e5be5a1e234d0f810885d9daf48ab72ff0 100644 (file)
@@ -8,9 +8,17 @@
  */
 
 #include "internal/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
index 9476a5fb665c9a1c31c9dc6a908e845c1428a216..6deee3b947df30e3fddbf51cd8f07a946ff8b703 100644 (file)
@@ -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_int(void);
-void ossl_deinit_casecmp(void);
 #endif
index c6c07127648f617da64c1ea7f8cf327ab361e338..408924f5ddeda345154cf8f429fda88f58417dd8 100644 (file)
@@ -157,5 +157,6 @@ char *ossl_ipaddr_to_asc(unsigned char *p, int len);
 char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);
 unsigned char *ossl_hexstr2buf_sep(const char *str, long *buflen,
                                    const char sep);
-
+int ossl_init_casecmp_int(void);
+void ossl_deinit_casecmp(void);
 #endif