• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 
7 #define __CRT__NO_INLINE
8 #include <stddef.h>
9 
memcmp(const void * _S1,const void * _S2,size_t _N)10 int __cdecl memcmp(const void *_S1, const void *_S2, size_t _N)
11 {
12     const unsigned char *s1 = _S1, *s2 = _S2;
13 
14     if (_N == 0 || s1 == s2)
15 	return 0;	/* even for NULL pointers */
16 
17     if ((s1 != NULL) != (s2 != NULL))
18 	return s2 == NULL ? 1 : -1;	/* robust */
19 
20     for ( ; 0 < _N; ++s1, ++s2, --_N)
21 	if (*s1 != *s2)
22 	    return (*s1 < *s2 ? -1 : +1);
23 
24     return 0;
25 }
26 
27