OSDN Git Service

Adjust repository version following WSL-5.2.2 release.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / wmemcmp.c
1 /*      This source code was extracted from the Q8 package created and placed
2     in the PUBLIC DOMAIN by Doug Gwyn <gwyn@arl.mil>
3     last edit:  1999/11/05      gwyn@arl.mil
4
5     Implements subclause 7.24 of ISO/IEC 9899:1999 (E).
6
7         It supports an encoding where all char codes are mapped
8         to the *same* code values within a wchar_t or wint_t,
9         so long as no other wchar_t codes are used by the program.
10
11 */
12
13 #include        <wchar.h>
14
15 int
16 wmemcmp(s1, s2, n)
17         register const wchar_t  *s1;
18         register const wchar_t  *s2;
19         size_t                          n;
20         {
21         if ( n == 0 || s1 == s2 )
22                 return 0;               /* even for NULL pointers */
23
24         if ( (s1 != NULL) != (s2 != NULL) )
25                 return s2 == NULL ? 1 : -1;     /* robust */
26
27         for ( ; n > 0; ++s1, ++s2, --n )
28                 if ( *s1 != *s2 )
29                         return *s1 - *s2;
30
31         return 0;
32         }