3bcbb94939113be14589a53b93abd4aa0385dc20
[debian/amanda] / common-src / strncasecmp.c
1
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5
6 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
7 #include <string.h>
8 #else
9 #include <strings.h>
10 #endif
11
12 /*
13  * The following function compares the first 'n' characters in 's1'
14  * and 's2' without considering case. It returns less than, equal to
15  * or greater than zero if 's1' is lexicographically less than, equal
16  * to or greater than 's2'.
17  */
18
19 int
20 strncasecmp(s1, s2, n)
21       const char *s1;
22       const char *s2;
23       size_t n;
24 {
25   unsigned char c1, c2;
26
27   if ( (s1 == s2 ) || (n == 0) ) 
28   {
29       /*
30        * the arguments are identical or there are no characters to be
31        * compared
32        */
33       return 0;
34   }
35
36   while (n > 0)
37   {
38       c1 = (unsigned char)tolower(*s1++);
39       c2 = (unsigned char)tolower(*s2++);
40
41       if (c1 != c2)
42       {
43           return(c1 - c2);
44       }
45
46       n--;
47   }
48
49   return(0);
50 }