Update copyright dates with scripts/update-copyrights.
[platform/upstream/glibc.git] / wcsmbs / wmemcmp.c
1 /* Copyright (C) 1996-2015 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
4
5    The GNU C Library is free software; you can redistribute it and/or
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.
9
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
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #include <wchar.h>
20
21 #ifndef WMEMCMP
22 # define WMEMCMP wmemcmp
23 #endif
24
25 int
26 WMEMCMP (s1, s2, n)
27      const wchar_t *s1;
28      const wchar_t *s2;
29      size_t n;
30 {
31   wchar_t c1;
32   wchar_t c2;
33
34   while (n >= 4)
35     {
36       c1 = s1[0];
37       c2 = s2[0];
38       if (c1 - c2 != 0)
39         return c1 > c2 ? 1 : -1;
40       c1 = s1[1];
41       c2 = s2[1];
42       if (c1 - c2 != 0)
43         return c1 > c2 ? 1 : -1;
44       c1 = s1[2];
45       c2 = s2[2];
46       if (c1 - c2 != 0)
47         return c1 > c2 ? 1 : -1;
48       c1 = s1[3];
49       c2 = s2[3];
50       if (c1 - c2 != 0)
51         return c1 > c2 ? 1 : -1;
52       s1 += 4;
53       s2 += 4;
54       n -= 4;
55     }
56
57   if (n > 0)
58     {
59       c1 = s1[0];
60       c2 = s2[0];
61       if (c1 - c2 != 0)
62         return c1 > c2 ? 1 : -1;
63       ++s1;
64       ++s2;
65       --n;
66     }
67   if (n > 0)
68     {
69       c1 = s1[0];
70       c2 = s2[0];
71       if (c1 - c2 != 0)
72         return c1 > c2 ? 1 : -1;
73       ++s1;
74       ++s2;
75       --n;
76     }
77   if (n > 0)
78     {
79       c1 = s1[0];
80       c2 = s2[0];
81       if (c1 - c2 != 0)
82         return c1 > c2 ? 1 : -1;
83     }
84
85   return 0;
86 }