substr.c revision 1219:f89f56c2d9ac
1184610Salfred/*
2184610Salfred * CDDL HEADER START
3184610Salfred *
4184610Salfred * The contents of this file are subject to the terms of the
5184610Salfred * Common Development and Distribution License, Version 1.0 only
6184610Salfred * (the "License").  You may not use this file except in compliance
7184610Salfred * with the License.
8184610Salfred *
9184610Salfred * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10184610Salfred * or http://www.opensolaris.org/os/licensing.
11184610Salfred * See the License for the specific language governing permissions
12184610Salfred * and limitations under the License.
13184610Salfred *
14184610Salfred * When distributing Covered Code, include this CDDL HEADER in each
15184610Salfred * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16184610Salfred * If applicable, add the following below this CDDL HEADER, with the
17184610Salfred * fields enclosed by brackets "[]" replaced with your own identifying
18184610Salfred * information: Portions Copyright [yyyy] [name of copyright owner]
19184610Salfred *
20184610Salfred * CDDL HEADER END
21184610Salfred */
22184610Salfred
23184610Salfred/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24184610Salfred/*	  All Rights Reserved  	*/
25184610Salfred
26184610Salfred/*
27184610Salfred * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
28184610Salfred * Use is subject to license terms.
29184610Salfred */
30184610Salfred
31184610Salfred#pragma ident	"%Z%%M%	%I%	%E% SMI"
32184610Salfred/*LINTLIBRARY*/
33184610Salfred
34184610Salfred#include "c_synonyms.h"
35184610Salfred#include <sys/types.h>
36184610Salfred#include "libmail.h"
37184610Salfred
38184610Salfred/*
39184610Salfred *	This routine looks for string2 in string1.
40184610Salfred *	If found, it returns the position string2 is found at,
41184610Salfred *	otherwise it returns a -1.
42184610Salfred */
43184610Salfredint
44184610Salfredsubstr(char *string1, char *string2)
45184610Salfred{
46184610Salfred	int i, j, len1, len2;
47184610Salfred
48184610Salfred	/* the size of the substring will always fit into an int */
49184610Salfred	/*LINTED*/
50184610Salfred	len1 = (int)strlen(string1);
51184610Salfred	/*LINTED*/
52184610Salfred	len2 = (int)strlen(string2);
53184610Salfred	for (i = 0; i < len1 - len2 + 1; i++) {
54184610Salfred		for (j = 0; j < len2 && string1[i+j] == string2[j]; j++);
55194677Sthompsa		if (j == len2)
56194677Sthompsa			return (i);
57194677Sthompsa	}
58194677Sthompsa	return (-1);
59194677Sthompsa}
60194677Sthompsa