On 1/23/19 3:26 AM, Liu Hao wrote:
在 2019/1/23 9:27, Zebediah Figura 写道:
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
---

+
+int __cdecl memcmp(const void *_S1, const void *_S2, size_t _N)
+{
+    const char *s1 = _S1, *s2 = _S2;
+

I have requested you use `unsigned char *` here or you will get
erroneous results because `char` is signed by default on Windows.


Sorry, will fix that (again...)

+    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;
+}
+






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

Reply via email to