libDtSearch: Coverity 86579
[oweals/cde.git] / cde / lib / csa / ansi_c.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: ansi_c.c /main/1 1996/04/21 19:25:03 drk $
24  *
25  * (c) Copyright 1996 Digital Equipment Corporation.
26  * (c) Copyright 1996 Hewlett-Packard Company.
27  * (c) Copyright 1996 International Business Machines Corp.
28  * (c) Copyright 1993-1996 Sun Microsystems, Inc.
29  * (c) Copyright 1996 Novell, Inc. 
30  * (c) Copyright 1996 FUJITSU LIMITED.
31  * (c) Copyright 1996 Hitachi.
32  */
33
34 #include <ctype.h>
35 #include "ansi_c.h"
36
37 #ifdef NEED_STRCASECMP
38 /*
39  * In case strcasecmp and strncasecmp are not provided by the system
40  * here are ones which do the trick.
41  */
42
43 int
44 strcasecmp(const char *s1,
45            const char *s2)
46 {
47     int c1, c2;
48
49     while (*s1 && *s2) {
50         c1 = isupper(*s1) ? tolower(*s1) : *s1;
51         c2 = isupper(*s2) ? tolower(*s2) : *s2;
52         if (c1 != c2)
53             return (c1 - c2);
54         s1++;
55         s2++;
56     }
57     return (int) (*s1 - *s2);
58 }
59
60
61 int
62 strncasecmp(const char *s1,
63             const char *s2,
64             size_t count)
65 {
66     int c1, c2;
67
68     if (!count)
69       return 0;
70
71     while (*s1 && *s2) {
72         c1 = isupper(*s1) ? tolower(*s1) : *s1;
73         c2 = isupper(*s2) ? tolower(*s2) : *s2;
74         if ((c1 != c2) || (! --count))
75             return (c1 - c2);
76         s1++;
77         s2++;
78     }
79     return (int) (*s1 - *s2);
80 }
81 #else
82 int ansi_c_strcasecmp_not_needed = 0;           /* Make the compiler happy. */
83 #endif