xref: /titanic_51/usr/src/lib/libmail/common/substr.c (revision 749f21d359d8fbd020c974a1a5227316221bfc9c)
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 #include "c_synonyms.h"
35 #include <sys/types.h>
36 #include "libmail.h"
37 
38 /*
39  *	This routine looks for string2 in string1.
40  *	If found, it returns the position string2 is found at,
41  *	otherwise it returns a -1.
42  */
43 int
44 substr(char *string1, char *string2)
45 {
46 	int i, j, len1, len2;
47 
48 	/* the size of the substring will always fit into an int */
49 	/*LINTED*/
50 	len1 = (int)strlen(string1);
51 	/*LINTED*/
52 	len2 = (int)strlen(string2);
53 	for (i = 0; i < len1 - len2 + 1; i++) {
54 		for (j = 0; j < len2 && string1[i+j] == string2[j]; j++);
55 		if (j == len2)
56 			return (i);
57 	}
58 	return (-1);
59 }
60