annotate liboctave/strncase.c @ 6469:a848b846cb3a ss-2-9-10

[project @ 2007-03-27 18:42:11 by jwe]
author jwe
date Tue, 27 Mar 2007 18:42:11 +0000
parents ed81d74118bb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6111
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
1 /* Copyright (C) 1992 Free Software Foundation, Inc.
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
2 This file is part of the GNU C Library.
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
3
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
4 The GNU C Library is free software; you can redistribute it and/or
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
5 modify it under the terms of the GNU General Public License as
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
6 published by the Free Software Foundation; either version 2 of the
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
7 License, or (at your option) any later version.
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
8
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
9 The GNU C Library is distributed in the hope that it will be useful,
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
12 General Public License for more details.
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
13
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
14 You should have received a copy of the GNU General Public
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
15 License along with the GNU C Library; see the file COPYING. If
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
16 not, write to the Free Software Foundation, Inc., 51 Franklin Street,
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
17 Fifth Floor, Boston, MA 02110-1301, USA. */
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
18
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
20 #include <config.h>
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
21 #endif
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
22
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
23 #ifndef HAVE_STRNCASECMP
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
24
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
25 #include <ctype.h>
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
26 #include <string.h>
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
27
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
28 /* Compare no more than N characters of S1 and S2,
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
29 ignoring case, returning less than, equal to or
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
30 greater than zero if S1 is lexicographically less
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
31 than, equal to or greater than S2. */
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
32 int
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
33 strncasecmp (const char *s1, const char *s2, size_t n)
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
34 {
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
35 register const unsigned char *p1 = (const unsigned char *) s1;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
36 register const unsigned char *p2 = (const unsigned char *) s2;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
37 unsigned char c1, c2;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
38
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
39 if (p1 == p2 || n == 0)
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
40 return 0;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
41
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
42 do
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
43 {
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
44 c1 = tolower (*p1++);
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
45 c2 = tolower (*p2++);
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
46 if (c1 == '\0' || c1 != c2)
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
47 return c1 - c2;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
48 } while (--n > 0);
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
49
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
50 return c1 - c2;
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
51 }
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
52
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents:
diff changeset
53 #endif