aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/mingw/misc/wmemcmp.c
blob: 5917b5a62ac59d0dbfb3d3a2b383427a95dde3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * 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.
 */
/*	This source code was extracted from the Q8 package created and placed
    in the PUBLIC DOMAIN by Doug Gwyn <gwyn@arl.mil>
    last edit:	1999/11/05	gwyn@arl.mil

    Implements subclause 7.24 of ISO/IEC 9899:1999 (E).

	It supports an encoding where all char codes are mapped
	to the *same* code values within a wchar_t or wint_t,
	so long as no other wchar_t codes are used by the program.

*/

#define __CRT__NO_INLINE
#include	<wchar.h>

#if 0
int
wmemcmp(s1, s2, n)
	register const wchar_t	*s1;
	register const wchar_t	*s2;
	size_t				n;
{
	if ( n == 0 || s1 == s2 )
		return 0;		/* even for NULL pointers */

	if ( (s1 != NULL) != (s2 != NULL) )
		return s2 == NULL ? 1 : -1;	/* robust */

	for ( ; n > 0; ++s1, ++s2, --n )
		if ( *s1 != *s2 )
			return *s1 - *s2;

	return 0;
}
#endif

int __cdecl wmemcmp(const wchar_t *_S1,const wchar_t *_S2,size_t _N)
{
	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;
}