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