Here are the updated patch files.
From f373089471ec8101d274851689ad65dde270f0e1 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbap...@gmail.com>
Date: Wed, 16 Mar 2022 19:51:27 +0530
Subject: [PATCH 1/2] crt: Add comsupp library

Required for unrar project

Signed-off-by: Biswapriyo Nath <nathbap...@gmail.com>
---
 mingw-w64-crt/Makefile.am        | 17 ++++++
 mingw-w64-crt/libsrc/comsupp.cpp | 93 ++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 mingw-w64-crt/libsrc/comsupp.cpp

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 305d1b9..6b3382c 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -95,6 +95,7 @@ src_dfp_math =
 endif
 
 src_libbits=libsrc/bits.c
+src_libcomsupp=libsrc/comsupp.cpp
 src_libshell32=libsrc/shell32.c
 src_libdinput=libsrc/dinput_kbd.c libsrc/dinput_joy.c libsrc/dinput_joy2.c 
libsrc/dinput_mouse.c libsrc/dinput_mouse2.c
 src_libdinput8=libsrc/dinput_private.h libsrc/dinput_joy.c 
libsrc/dinput_joy2.c libsrc/dinput_mouse.c libsrc/dinput_mouse2.c 
libsrc/dinput_kbd.c
@@ -702,6 +703,10 @@ lib32_LIBRARIES += lib32/libbits.a
 lib32_libbits_a_SOURCES = $(src_libbits)
 lib32_libbits_a_CPPFLAGS=$(CPPFLAGS32) $(sysincludes)
 
+lib32_LIBRARIES += lib32/libcomsupp.a
+lib32_libcomsupp_a_SOURCES = $(src_libcomsupp)
+lib32_libcomsupp_a_CPPFLAGS=$(CPPFLAGS32) $(sysincludes)
+
 lib32_LIBRARIES += lib32/libshell32.a
 lib32_libshell32_a_SOURCES = $(src_libshell32)
 lib32_libshell32_a_AR = $(DTLIB32) && $(AR) $(ARFLAGS)
@@ -1033,6 +1038,10 @@ lib64_LIBRARIES += lib64/libbits.a
 lib64_libbits_a_SOURCES = $(src_libbits)
 lib64_libbits_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
 
+lib64_LIBRARIES += lib64/libcomsupp.a
+lib64_libcomsupp_a_SOURCES = $(src_libcomsupp)
+lib64_libcomsupp_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
+
 lib64_LIBRARIES += lib64/libshell32.a
 lib64_libshell32_a_SOURCES = $(src_libshell32)
 lib64_libshell32_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
@@ -1367,6 +1376,10 @@ libarm32_LIBRARIES += libarm32/libbits.a
 libarm32_libbits_a_SOURCES = $(src_libbits)
 libarm32_libbits_a_CPPFLAGS=$(CPPFLAGSARM32) $(sysincludes)
 
+libarm32_LIBRARIES += libarm32/libcomsupp.a
+libarm32_libcomsupp_a_SOURCES = $(src_libcomsupp)
+libarm32_libcomsupp_a_CPPFLAGS=$(CPPFLAGSARM32) $(sysincludes)
+
 libarm32_LIBRARIES += libarm32/libshell32.a
 libarm32_libshell32_a_SOURCES = $(src_libshell32)
 libarm32_libshell32_a_AR = $(DTDEFARM32) $(top_srcdir)/lib-common/shell32.def 
&& $(AR) $(ARFLAGS)
@@ -1649,6 +1662,10 @@ libarm64_LIBRARIES += libarm64/libbits.a
 libarm64_libbits_a_SOURCES = $(src_libbits)
 libarm64_libbits_a_CPPFLAGS=$(CPPFLAGSARM64) $(sysincludes)
 
+libarm64_LIBRARIES += libarm64/libcomsupp.a
+libarm64_libcomsupp_a_SOURCES = $(src_libcomsupp)
+libarm64_libcomsupp_a_CPPFLAGS=$(CPPFLAGSARM64) $(sysincludes)
+
 libarm64_LIBRARIES += libarm64/libshell32.a
 libarm64_libshell32_a_SOURCES = $(src_libshell32)
 libarm64_libshell32_a_AR = $(DTDEFARM64) $(top_srcdir)/lib-common/shell32.def 
&& $(AR) $(ARFLAGS)
diff --git a/mingw-w64-crt/libsrc/comsupp.cpp b/mingw-w64-crt/libsrc/comsupp.cpp
new file mode 100644
index 0000000..127e597
--- /dev/null
+++ b/mingw-w64-crt/libsrc/comsupp.cpp
@@ -0,0 +1,93 @@
+/*
+ * PROJECT:     ReactOS crt library
+ * LICENSE:     BSD-2-Clause (https://spdx.org/licenses/BSD-2-Clause)
+ * PURPOSE:     Compiler support for COM
+ * COPYRIGHT:   Copyright 2013 Thomas Faber (thomas.fa...@reactos.org)
+ *              Copyright 2015 Hermès Bélusca-Maïto 
(hermes.belusca-ma...@reactos.org)
+ */
+
+#include <windows.h>
+#include <comdef.h>
+
+/* From 
https://github.com/reactos/reactos/blob/master/sdk/lib/comsupp/comsupp.cpp */
+namespace _com_util
+{
+
+BSTR WINAPI ConvertStringToBSTR(const char *pSrc)
+{
+    DWORD cwch;
+    BSTR wsOut(NULL);
+
+    if (!pSrc) return NULL;
+
+    /* Compute the needed size with the NULL terminator */
+    cwch = ::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, NULL, 0);
+    if (cwch == 0) return NULL;
+
+    /* Allocate the BSTR (without the NULL terminator) */
+    wsOut = ::SysAllocStringLen(NULL, cwch - 1);
+    if (!wsOut)
+    {
+        ::_com_issue_error(HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY));
+        return NULL;
+    }
+
+    /* Convert the string */
+    if (::MultiByteToWideChar(CP_ACP, 0, pSrc, -1, wsOut, cwch) == 0)
+    {
+        /* We failed, clean everything up */
+        cwch = ::GetLastError();
+
+        ::SysFreeString(wsOut);
+        wsOut = NULL;
+
+        ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
+    }
+
+    return wsOut;
+}
+
+char* WINAPI ConvertBSTRToString(BSTR pSrc)
+{
+    DWORD cb, cwch;
+    char *szOut = NULL;
+
+    if (!pSrc) return NULL;
+
+    /* Retrieve the size of the BSTR with the NULL terminator */
+    cwch = ::SysStringLen(pSrc) + 1;
+
+    /* Compute the needed size with the NULL terminator */
+    cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, NULL, 0, NULL, NULL);
+    if (cb == 0)
+    {
+        cwch = ::GetLastError();
+        ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
+        return NULL;
+    }
+
+    /* Allocate the string */
+    szOut = (char*)::operator new(cb * sizeof(char));
+    if (!szOut)
+    {
+        ::_com_issue_error(HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY));
+        return NULL;
+    }
+
+    /* Convert the string and NULL-terminate */
+    szOut[cb - 1] = '\0';
+    if (::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch, szOut, cb, NULL, NULL) == 
0)
+    {
+        /* We failed, clean everything up */
+        cwch = ::GetLastError();
+
+        ::operator delete(szOut);
+        szOut = NULL;
+
+        ::_com_issue_error(!IS_ERROR(cwch) ? HRESULT_FROM_WIN32(cwch) : cwch);
+    }
+
+    return szOut;
+}
+
+}
-- 
2.35.1

From 6e558f746dee25d794bfc2d664af694996ab7edd Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbap...@gmail.com>
Date: Wed, 16 Mar 2022 19:51:05 +0530
Subject: [PATCH 2/2] copying: Add BSD-2 license from ReactOS for comsupp library

Signed-off-by: Biswapriyo Nath <nathbap...@gmail.com>
---
 .../COPYING.MinGW-w64-runtime.txt             | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt 
b/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt
index ca6a077..dcf0807 100644
--- a/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt
+++ b/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt
@@ -238,3 +238,33 @@ This library is distributed in the hope that it will be 
useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
+
+=================================
+comsupp: Compiler support for COM
+=================================
+
+BSD 2-Clause License
+
+Copyright 2013 Thomas Faber (thomas.fa...@reactos.org)
+Copyright 2015 Hermès Bélusca-Maïto (hermes.belusca-ma...@reactos.org)
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- 
2.35.1

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to