2016-01-05 00:05:18 +08:00
|
|
|
/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
|
1996-12-20 09:39:50 +08:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
|
1996-02-08 18:00:34 +08:00
|
|
|
|
1996-12-20 09:39:50 +08:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 12:58:11 +08:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1996-02-08 18:00:34 +08:00
|
|
|
|
1996-12-20 09:39:50 +08:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 12:58:11 +08:00
|
|
|
Lesser General Public License for more details.
|
1996-02-08 18:00:34 +08:00
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1996-02-08 18:00:34 +08:00
|
|
|
|
1996-04-04 00:31:49 +08:00
|
|
|
#include <wchar.h>
|
1996-02-08 18:00:34 +08:00
|
|
|
|
2015-08-26 16:26:22 +08:00
|
|
|
#ifndef WCSNCMP
|
|
|
|
# define WCSNCMP wcsncmp
|
|
|
|
#endif
|
1996-02-08 18:00:34 +08:00
|
|
|
|
|
|
|
/* Compare no more than N characters of S1 and S2,
|
|
|
|
returning less than, equal to or greater than zero
|
1996-12-20 09:39:50 +08:00
|
|
|
if S1 is lexicographically less than, equal to or
|
1996-02-08 18:00:34 +08:00
|
|
|
greater than S2. */
|
|
|
|
int
|
2015-10-17 04:21:49 +08:00
|
|
|
WCSNCMP (const wchar_t *s1, const wchar_t *s2, size_t n)
|
1996-02-08 18:00:34 +08:00
|
|
|
{
|
2015-04-14 03:23:10 +08:00
|
|
|
wchar_t c1 = L'\0';
|
|
|
|
wchar_t c2 = L'\0';
|
1996-02-08 18:00:34 +08:00
|
|
|
|
|
|
|
if (n >= 4)
|
|
|
|
{
|
|
|
|
size_t n4 = n >> 2;
|
|
|
|
do
|
|
|
|
{
|
2015-04-14 03:23:10 +08:00
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
1996-02-08 18:00:34 +08:00
|
|
|
if (c1 == L'\0' || c1 != c2)
|
2015-04-14 03:23:10 +08:00
|
|
|
return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
|
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
1996-02-08 18:00:34 +08:00
|
|
|
if (c1 == L'\0' || c1 != c2)
|
2015-04-14 03:23:10 +08:00
|
|
|
return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
|
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
1996-02-08 18:00:34 +08:00
|
|
|
if (c1 == L'\0' || c1 != c2)
|
2015-04-14 03:23:10 +08:00
|
|
|
return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
|
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
1996-02-08 18:00:34 +08:00
|
|
|
if (c1 == L'\0' || c1 != c2)
|
2015-04-14 03:23:10 +08:00
|
|
|
return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
|
1996-02-08 18:00:34 +08:00
|
|
|
} while (--n4 > 0);
|
|
|
|
n &= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n > 0)
|
|
|
|
{
|
2015-04-14 03:23:10 +08:00
|
|
|
c1 = *s1++;
|
|
|
|
c2 = *s2++;
|
1996-02-08 18:00:34 +08:00
|
|
|
if (c1 == L'\0' || c1 != c2)
|
2015-04-14 03:23:10 +08:00
|
|
|
return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0);
|
1996-02-08 18:00:34 +08:00
|
|
|
n--;
|
|
|
|
}
|
|
|
|
|
2015-04-14 03:23:10 +08:00
|
|
|
return 0;
|
1996-02-08 18:00:34 +08:00
|
|
|
}
|