Update NEWS
[glibc.git] / wcsmbs / wmemcmp.c
blobbedb89335e5caff9e1b2c277afcd5075254fe881
1 /* Copyright (C) 1996-2013 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.
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.
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.
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/>. */
19 #include <wchar.h>
21 #ifndef WMEMCMP
22 # define WMEMCMP wmemcmp
23 #endif
25 int
26 WMEMCMP (s1, s2, n)
27 const wchar_t *s1;
28 const wchar_t *s2;
29 size_t n;
31 register wchar_t c1;
32 register wchar_t c2;
34 while (n >= 4)
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;
57 if (n > 0)
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;
67 if (n > 0)
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;
77 if (n > 0)
79 c1 = s1[0];
80 c2 = s2[0];
81 if (c1 - c2 != 0)
82 return c1 > c2 ? 1 : -1;
85 return 0;