Update.
[platform/upstream/glibc.git] / wcsmbs / wmemcmp.c
1 /* Copyright (C) 1996, 1997 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <wchar.h>
21
22
23 int
24 wmemcmp (s1, s2, n)
25      const wchar_t *s1;
26      const wchar_t *s2;
27      size_t n;
28 {
29   register wint_t c1;
30   register wint_t c2;
31
32   while (n >= 4)
33     {
34       c1 = (wint_t) s1[0];
35       c2 = (wint_t) s2[0];
36       if (c1 - c2 != 0)
37         return c1 - c2;
38       c1 = (wint_t) s1[1];
39       c2 = (wint_t) s2[1];
40       if (c1 - c2 != 0)
41         return c1 - c2;
42       c1 = (wint_t) s1[2];
43       c2 = (wint_t) s2[2];
44       if (c1 - c2 != 0)
45         return c1 - c2;
46       c1 = (wint_t) s1[3];
47       c2 = (wint_t) s2[3];
48       if (c1 - c2 != 0)
49         return c1 - c2;
50       s1 += 4;
51       s2 += 4;
52       n -= 4;
53     }
54
55   if (n > 0)
56     {
57       c1 = (wint_t) s1[0];
58       c2 = (wint_t) s2[0];
59       if (c1 - c2 != 0)
60         return c1 - c2;
61       ++s1;
62       ++s2;
63       --n;
64     }
65   if (n > 0)
66     {
67       c1 = (wint_t) s1[0];
68       c2 = (wint_t) s2[0];
69       if (c1 - c2 != 0)
70         return c1 - c2;
71       ++s1;
72       ++s2;
73       --n;
74     }
75   if (n > 0)
76     {
77       c1 = (wint_t) s1[0];
78       c2 = (wint_t) s2[0];
79       if (c1 - c2 != 0)
80         return c1 - c2;
81     }
82
83   return 0;
84 }