]> git.ipfire.org Git - thirdparty/glibc.git/blame - wcsmbs/wmemcmp.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / wcsmbs / wmemcmp.c
CommitLineData
bfff8b1b 1/* Copyright (C) 1996-2017 Free Software Foundation, Inc.
33a934a3
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
30de3b18 4
33a934a3 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
30de3b18 9
33a934a3
UD
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
30de3b18 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
30de3b18
RM
18
19#include <wchar.h>
20
be13f7bf 21#ifndef WMEMCMP
b468825a 22# define WMEMCMP wmemcmp
be13f7bf 23#endif
30de3b18
RM
24
25int
9d46370c 26WMEMCMP (const wchar_t *s1, const wchar_t *s2, size_t n)
30de3b18 27{
2e09a79a
JM
28 wchar_t c1;
29 wchar_t c2;
30de3b18
RM
30
31 while (n >= 4)
32 {
1f1e1947
AS
33 c1 = s1[0];
34 c2 = s2[0];
30de3b18 35 if (c1 - c2 != 0)
be13f7bf 36 return c1 > c2 ? 1 : -1;
1f1e1947
AS
37 c1 = s1[1];
38 c2 = s2[1];
30de3b18 39 if (c1 - c2 != 0)
be13f7bf 40 return c1 > c2 ? 1 : -1;
1f1e1947
AS
41 c1 = s1[2];
42 c2 = s2[2];
30de3b18 43 if (c1 - c2 != 0)
be13f7bf 44 return c1 > c2 ? 1 : -1;
1f1e1947
AS
45 c1 = s1[3];
46 c2 = s2[3];
30de3b18 47 if (c1 - c2 != 0)
be13f7bf 48 return c1 > c2 ? 1 : -1;
30de3b18
RM
49 s1 += 4;
50 s2 += 4;
51 n -= 4;
52 }
53
54 if (n > 0)
55 {
1f1e1947
AS
56 c1 = s1[0];
57 c2 = s2[0];
30de3b18 58 if (c1 - c2 != 0)
be13f7bf 59 return c1 > c2 ? 1 : -1;
30de3b18
RM
60 ++s1;
61 ++s2;
62 --n;
63 }
64 if (n > 0)
65 {
1f1e1947
AS
66 c1 = s1[0];
67 c2 = s2[0];
30de3b18 68 if (c1 - c2 != 0)
be13f7bf 69 return c1 > c2 ? 1 : -1;
30de3b18
RM
70 ++s1;
71 ++s2;
72 --n;
73 }
74 if (n > 0)
75 {
1f1e1947
AS
76 c1 = s1[0];
77 c2 = s2[0];
30de3b18 78 if (c1 - c2 != 0)
be13f7bf 79 return c1 > c2 ? 1 : -1;
30de3b18
RM
80 }
81
82 return 0;
83}