1 /*
2 Copyright (c) 1994 Cygnus Support.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 at Cygnus Support, Inc. Cygnus Support, Inc. may not be used to
11 endorse or promote products derived from this software without
12 specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17 /*
18 FUNCTION
19 <<strcasecmp>>---case-insensitive character string compare
20
21 INDEX
22 strcasecmp
23
24 SYNOPSIS
25 #include <strings.h>
26 int strcasecmp(const char *<[a]>, const char *<[b]>);
27
28 DESCRIPTION
29 <<strcasecmp>> compares the string at <[a]> to
30 the string at <[b]> in a case-insensitive manner.
31
32 RETURNS
33
34 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
35 both are converted to lowercase), <<strcasecmp>> returns a
36 number greater than zero. If the two strings match,
37 <<strcasecmp>> returns zero. If <<*<[a]>>> sorts
38 lexicographically before <<*<[b]>>>, <<strcasecmp>> returns a
39 number less than zero.
40
41 PORTABILITY
42 <<strcasecmp>> is in the Berkeley Software Distribution.
43
44 <<strcasecmp>> requires no supporting OS subroutines. It uses
45 tolower() from elsewhere in this library.
46
47 QUICKREF
48 strcasecmp
49 */
50
51 #include <strings.h>
52 #include <ctype.h>
53
54 int
strcasecmp(const char * s1,const char * s2)55 strcasecmp (const char *s1,
56 const char *s2)
57 {
58 int d = 0;
59 for ( ; ; )
60 {
61 const int c1 = tolower(*s1++);
62 const int c2 = tolower(*s2++);
63 if (((d = c1 - c2) != 0) || (c2 == '\0'))
64 break;
65 }
66 return d;
67 }
68