在 2018/12/19 3:47, Zebediah Figura 写道:
> This provides memcmp() for kernel-mode drivers, which for some reason is not
> export from ntoskrnl like other crt functions.
> 
> The implementation was copied from wmemcmp.c in libmingwex.
> 
> Signed-off-by: Zebediah Figura <[email protected]>
> ---
>  mingw-w64-crt/Makefile.am     |  9 +++++++++
>  mingw-w64-crt/libsrc/memcmp.c | 24 ++++++++++++++++++++++++
>  2 files changed, 33 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 f8b0623c..fc020bcf 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 =
> @@ -966,6 +971,10 @@ lib64_LIBRARIES += lib64/libtaskschd.a
>  lib64_libtaskschd_a_SOURCES = $(src_libtaskschd)
>  lib64_libtaskschd_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
>  
> +lib64_LIBRARIES += lib64/libmemcmp.a
> +lib64_libmemcmp_a_SOURCES = $(src_libmemcmp)
> +lib64_libmemcmp_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
> +
>  if !W32API
>  lib64_LIBRARIES += lib64/libdelayimp.a
>  lib64_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..7f465aba
> --- /dev/null
> +++ b/mingw-w64-crt/libsrc/memcmp.c
> @@ -0,0 +1,24 @@
> +/**
> + * 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 unsigned char *_S1, const unsigned char *_S2, 
> size_t _N)
> +{

The types of the first two parameters of `memcmp()` are both `const void
*`. Please don't write `const unsigned char *` there; rather, cast the
parameters to `const unsigned char *` in the body, so the definition
will not disagree with previous declarations brought in by <stddef.h>,
if there were any.

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


-- 
Best regards,
LH_Mouse

Attachment: signature.asc
Description: OpenPGP digital signature

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

Reply via email to