File openssl-1.1-fix-mingw-compile.patch of Package mingw32-openssl-1_1

--- ./crypto/fips/fips.c.orig	2020-06-11 15:07:13.626347944 +0000
+++ ./crypto/fips/fips.c	2020-06-11 15:09:50.761949715 +0000
@@ -310,6 +310,62 @@
     return rv;
 }
 
+#if defined(_WIN32) &&  defined(_GNU_SOURCE)
+/* https://stackoverflow.com/questions/735126/are-there-alternate-implementations-of-gnu-getline-interface/735472#735472 */
+static size_t getline(char **lineptr, size_t *n, FILE *stream)
+{
+    char *bufptr = NULL;
+    char *p = bufptr;
+    size_t size;
+    int c;
+
+    if (lineptr == NULL) {
+        return -1;
+    }
+    if (stream == NULL) {
+        return -1;
+    }
+    if (n == NULL) {
+        return -1;
+    }
+    bufptr = *lineptr;
+    size = *n;
+
+    c = fgetc(stream);
+    if (c == EOF) {
+        return -1;
+    }
+    if (bufptr == NULL) {
+        bufptr = malloc(128);
+        if (bufptr == NULL) {
+            return -1;
+        }
+        size = 128;
+    }
+    p = bufptr;
+    while(c != EOF) {
+        if ((p - bufptr) > (size - 1)) {
+            size = size + 128;
+            bufptr = realloc(bufptr, size);
+            if (bufptr == NULL) {
+                return -1;
+            }
+        }
+        *p++ = c;
+        if (c == '\n') {
+            break;
+        }
+        c = fgetc(stream);
+    }
+
+    *p++ = '\0';
+    *lineptr = bufptr;
+    *n = size;
+
+    return p - bufptr - 1;
+}
+
+
 static int FIPSCHECK_verify(const char *path)
 {
     int rv = 0;
@@ -367,6 +423,7 @@
     /* check successful */
     return 1;
 }
+#endif
 
 static int verify_checksums(void)
 {
--- ./crypto/fips/fips.c.orig	2020-06-11 15:17:20.740846803 +0000
+++ ./crypto/fips/fips.c	2020-06-11 15:21:08.504309404 +0000
@@ -221,6 +221,16 @@
     return hex;
 }
 
+#if defined(_WIN32) && defined(_GNU_SOURCE)
+char *stpcpy(char *_Dest,const char *_Source)
+{
+  for (; *_Source; _Source++, _Dest++)
+    *_Dest = *_Source;
+  *_Dest = '\0';
+  return _Dest;
+}
+#endif
+
 # define HMAC_PREFIX "."
 # ifndef HMAC_SUFFIX
 #  define HMAC_SUFFIX ".hmac"
--- ./crypto/o_init.c.orig	2020-06-11 15:24:58.063738402 +0000
+++ ./crypto/o_init.c	2020-06-11 15:17:20.724846840 +0000
@@ -24,6 +24,11 @@
 
 # define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
 
+#if defined(_WIN32) && defined(_GNU_SOURCE)
+/* Windows does not support the request security model */
+#define secure_getenv getenv
+#endif
+
 static void init_fips_mode(void)
 {
     char buf[2] = "0";
--- ./crypto/fips/fips.c.orig	2020-06-12 06:40:48.738477066 +0000
+++ ./crypto/fips/fips.c	2020-06-12 06:46:33.753240397 +0000
@@ -98,6 +98,15 @@
 # define fips_r_lock()   CRYPTO_THREAD_read_lock(fips_lock)
 # define fips_r_unlock() CRYPTO_THREAD_unlock(fips_lock)
 
+const char *get_library_name_crypto(int versioned)
+{
+#if defined(_WIN32) && defined(_GNU_SOURCE)
+    return versioned ? "libcrypto-1_1.dll" : "libcrypto.dll";
+#else
+    return versioned ? "libcrypto.so." SHLIB_VERSION_NUMBER : "libcrypto.so";
+#endif
+}
+
 static void fips_set_mode(int onoff)
 {
     int owning_thread = fips_is_owning_thread();
@@ -444,7 +452,7 @@
     /* we need to avoid dlopening libssl, assume both libcrypto and libssl
        are in the same directory */

-    rv = get_library_path("libcrypto.so." SHLIB_VERSION_NUMBER,
+    rv = get_library_path(get_library_name_crypto(1),
                           "FIPS_mode_set", path, sizeof(path));
     if (rv < 0)
         return 0;
@@ -454,7 +462,7 @@
         return 0;
 
     /* replace libcrypto with libssl */
-    while ((p = strstr(path, "libcrypto.so")) != NULL) {
+    while ((p = strstr(path, get_library_name_crypto(0))) != NULL) {
         p = stpcpy(p, "libssl");
         memmove(p, p + 3, strlen(p + 2));
     }
@@ -564,7 +572,7 @@
         if (fips_selftest_fail)
 	     {
                 /* check if the checksum files are installed */
-                rv = get_library_path("libcrypto.so." SHLIB_VERSION_NUMBER, "FIPS_mode_set", path, sizeof(path));
+                rv = get_library_path(get_library_name_crypto(1), "FIPS_mode_set", path, sizeof(path));
                 if (rv < 0)
                         OpenSSLDie(__FILE__,__LINE__, "FATAL FIPS SELFTEST FAILURE");
 
--- ./crypto/o_str.c.orig	2020-06-19 20:50:21.234096454 +0000
+++ ./crypto/o_str.c	2020-06-19 20:50:40.490760727 +0000
@@ -237,7 +237,7 @@
 
 int openssl_strerror_r(int errnum, char *buf, size_t buflen)
 {
-#if defined(_MSC_VER) && _MSC_VER>=1400 && !defined(_WIN32_WCE)
+#if (defined(_MSC_VER) && _MSC_VER>=1400 && !defined(_WIN32_WCE)) || defined(__MINGW32__)
     return !strerror_s(buf, buflen, errnum);
 #elif defined(_GNU_SOURCE)
     char *err;
--- openssl-1.1.1n/ssl/ssl_ciph.c.orig	2022-03-22 19:22:38.535457379 +0100
+++ openssl-1.1.1n/ssl/ssl_ciph.c	2022-03-22 19:22:57.767394830 +0100
@@ -11,6 +11,9 @@
 
 /* for secure_getenv */
 #define _GNU_SOURCE
+#if defined(_WIN32) && defined(_GNU_SOURCE)
+#define secure_getenv getenv
+#endif
 #include <stdio.h>
 #include <ctype.h>
 #include <openssl/objects.h>
openSUSE Build Service is sponsored by