Back to index

glibc  2.9
wmemcmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <wchar.h>
00021 
00022 
00023 int
00024 wmemcmp (s1, s2, n)
00025      const wchar_t *s1;
00026      const wchar_t *s2;
00027      size_t n;
00028 {
00029   register wint_t c1;
00030   register wint_t c2;
00031 
00032   while (n >= 4)
00033     {
00034       c1 = (wint_t) s1[0];
00035       c2 = (wint_t) s2[0];
00036       if (c1 - c2 != 0)
00037        return c1 - c2;
00038       c1 = (wint_t) s1[1];
00039       c2 = (wint_t) s2[1];
00040       if (c1 - c2 != 0)
00041        return c1 - c2;
00042       c1 = (wint_t) s1[2];
00043       c2 = (wint_t) s2[2];
00044       if (c1 - c2 != 0)
00045        return c1 - c2;
00046       c1 = (wint_t) s1[3];
00047       c2 = (wint_t) s2[3];
00048       if (c1 - c2 != 0)
00049        return c1 - c2;
00050       s1 += 4;
00051       s2 += 4;
00052       n -= 4;
00053     }
00054 
00055   if (n > 0)
00056     {
00057       c1 = (wint_t) s1[0];
00058       c2 = (wint_t) s2[0];
00059       if (c1 - c2 != 0)
00060        return c1 - c2;
00061       ++s1;
00062       ++s2;
00063       --n;
00064     }
00065   if (n > 0)
00066     {
00067       c1 = (wint_t) s1[0];
00068       c2 = (wint_t) s2[0];
00069       if (c1 - c2 != 0)
00070        return c1 - c2;
00071       ++s1;
00072       ++s2;
00073       --n;
00074     }
00075   if (n > 0)
00076     {
00077       c1 = (wint_t) s1[0];
00078       c2 = (wint_t) s2[0];
00079       if (c1 - c2 != 0)
00080        return c1 - c2;
00081     }
00082 
00083   return 0;
00084 }