This provides memcmp() for x86 kernel-mode drivers, which for some reason is
not exported from ntoskrnl like other CRT functions.

The implementation was copied and modified from wmemcmp.c in libmingwex.

v3: fix types, restrict to i386
---
 mingw-w64-crt/Makefile.am     |  5 +++++
 mingw-w64-crt/libsrc/memcmp.c | 26 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 mingw-w64-crt/libsrc/memcmp.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 10f3b04c..af37e99e 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -111,6 +111,7 @@ src_libsapi=libsrc/sapi.c
 src_libsensorsapi=libsrc/sensorsapi.c
 src_libportabledeviceguids=libsrc/portabledeviceguids.c
 src_libtaskschd=libsrc/taskschd.c
+src_libmemcmp=libsrc/memcmp.c
 
 src_libmingw32=include/oscalls.h include/internal.h include/sect_attribs.h \
   crt/crt0_c.c        crt/dll_argv.c  crt/gccmain.c     crt/natstart.c  
crt/pseudo-reloc-list.c  crt/wildcard.c \
@@ -632,6 +633,10 @@ lib32_LIBRARIES += lib32/libtaskschd.a
 lib32_libtaskschd_a_SOURCES = $(src_libtaskschd)
 lib32_libtaskschd_a_CPPFLAGS=$(CPPFLAGS32) $(sysincludes)
 
+lib32_LIBRARIES += lib32/libmemcmp.a
+lib32_libmemcmp_a_SOURCES = $(src_libmemcmp)
+lib32_libmemcmp_a_CPPFLAGS=$(CPPFLAGS32) $(sysincludes)
+
 if !W32API
 lib32_LIBRARIES += lib32/libdelayimp.a
 lib32_libdelayimp_a_SOURCES =
diff --git a/mingw-w64-crt/libsrc/memcmp.c b/mingw-w64-crt/libsrc/memcmp.c
new file mode 100644
index 00000000..868d42fd
--- /dev/null
+++ b/mingw-w64-crt/libsrc/memcmp.c
@@ -0,0 +1,26 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#define __CRT__NO_INLINE
+#include <stddef.h>
+
+int __cdecl memcmp(const void *_S1, const void *_S2, size_t _N)
+{
+    const char *s1 = _S1, *s2 = _S2;
+
+    if (_N == 0 || s1 == s2)
+       return 0;       /* even for NULL pointers */
+
+    if ((s1 != NULL) != (s2 != NULL))
+       return s2 == NULL ? 1 : -1;     /* robust */
+
+    for ( ; 0 < _N; ++s1, ++s2, --_N)
+       if (*s1 != *s2)
+           return (*s1 < *s2 ? -1 : +1);
+
+    return 0;
+}
+
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to