xref: /titanic_51/usr/src/lib/libmail/common/casncmp.c (revision 672986541be54a7a471bb088e60780c37e371d7e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 /*LINTLIBRARY*/
33 
34 /*
35  *  NAME
36  *	casncmp - compare strings ignoring case
37  *
38  *  SYNOPSIS
39  *	int casncmp(char *s1, char *s2, ssize_t n)
40  *
41  *  DESCRIPTION
42  *	Compare two strings ignoring case differences.
43  *	Stop after n bytes or the trailing NUL.
44  */
45 
46 #include "c_synonyms.h"
47 #include "libmail.h"
48 #include <ctype.h>
49 #include <sys/types.h>
50 
51 int
52 casncmp(char *s1, char *s2, ssize_t n)
53 {
54 	if (s1 == s2)
55 		return (0);
56 	while ((--n >= 0) && (tolower(*s1) == tolower(*s2))) {
57 		s2++;
58 		if (*s1++ == '\0')
59 			return (0);
60 	}
61 	return ((n < 0)? 0: (*s1 - *s2));
62 }
63