source: trunk/third/gettext/lib/strncasecmp.c @ 16931

Revision 16931, 2.2 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16930, which included commits to RCS files with non-trunk default branches.
Line 
1/* Compare at most N characters of two strings without taking care for
2   the case.
3   Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
4
5   NOTE: The canonical source of this file is maintained with the GNU C Library.
6   Bugs can be reported to bug-glibc@gnu.org.
7
8   This program is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by the
10   Free Software Foundation; either version 2, or (at your option) any
11   later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21   USA.  */
22
23#ifdef HAVE_CONFIG_H
24# include <config.h>
25#endif
26
27#include <string.h>
28#include <ctype.h>
29
30#ifndef weak_alias
31# define __strncasecmp strncasecmp
32# define TOLOWER(Ch) tolower (Ch)
33#else
34# ifdef USE_IN_EXTENDED_LOCALE_MODEL
35#  define __strncasecmp __strncasecmp_l
36#  define TOLOWER(Ch) __tolower_l ((Ch), loc)
37# else
38#  define TOLOWER(Ch) tolower (Ch)
39# endif
40#endif
41
42#ifdef USE_IN_EXTENDED_LOCALE_MODEL
43# define LOCALE_PARAM , loc
44# define LOCALE_PARAM_DECL __locale_t loc;
45#else
46# define LOCALE_PARAM
47# define LOCALE_PARAM_DECL
48#endif
49
50/* Compare no more than N characters of S1 and S2,
51   ignoring case, returning less than, equal to or
52   greater than zero if S1 is lexicographically less
53   than, equal to or greater than S2.  */
54int
55__strncasecmp (s1, s2, n LOCALE_PARAM)
56     const char *s1;
57     const char *s2;
58     size_t n;
59     LOCALE_PARAM_DECL
60{
61  const unsigned char *p1 = (const unsigned char *) s1;
62  const unsigned char *p2 = (const unsigned char *) s2;
63  unsigned char c1, c2;
64
65  if (p1 == p2 || n == 0)
66    return 0;
67
68  do
69    {
70      c1 = TOLOWER (*p1++);
71      c2 = TOLOWER (*p2++);
72      if (c1 == '\0' || c1 != c2)
73        return c1 - c2;
74    } while (--n > 0);
75
76  return c1 - c2;
77}
78#ifndef __strncasecmp
79weak_alias (__strncasecmp, strncasecmp)
80#endif
Note: See TracBrowser for help on using the repository browser.