Blame src/strstr.c

Packit f574b8
/*
Packit f574b8
 * strstr.c -- return the offset of one string within another.
Packit f574b8
 *
Packit f574b8
 * Copyright (C) 1997 Free Software Foundation, Inc.
Packit f574b8
 *
Packit f574b8
 * This program is free software; you can redistribute it and/or modify it under
Packit f574b8
 * the terms of the GNU General Public License as published by the Free
Packit f574b8
 * Software Foundation; either version 2, or (at your option) any later
Packit f574b8
 * version.
Packit f574b8
 *
Packit f574b8
 * This program is distributed in the hope that it will be useful, but WITHOUT
Packit f574b8
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit f574b8
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
Packit f574b8
 * more details.
Packit f574b8
 *
Packit f574b8
 * You should have received a copy of the GNU General Public License along with
Packit f574b8
 * this program; if not, write to the Free Software Foundation, Inc., 59
Packit f574b8
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Packit f574b8
 */
Packit f574b8
Packit f574b8
/* Written by Philippe De Muyter <phdm@macqel.be>.  */
Packit f574b8
Packit f574b8
/*
Packit f574b8
 * NAME
Packit f574b8
 *
Packit f574b8
 * strstr -- locate first occurrence of a substring
Packit f574b8
 *
Packit f574b8
 * SYNOPSIS
Packit f574b8
 *
Packit f574b8
 * char *strstr (char *s1, char *s2)
Packit f574b8
 *
Packit f574b8
 * DESCRIPTION
Packit f574b8
 *
Packit f574b8
 * Locates the first occurrence in the string pointed to by S1 of the string
Packit f574b8
 * pointed to by S2.  Returns a pointer to the substring found, or a NULL
Packit f574b8
 * pointer if not found.  If S2 points to a string with zero length, the
Packit f574b8
 * function returns S1.
Packit f574b8
 *
Packit f574b8
 * BUGS
Packit f574b8
 *
Packit f574b8
 */
Packit f574b8
Packit f574b8
char *strstr(char *buf, char *sub)
Packit f574b8
{
Packit f574b8
    register char *bp;
Packit f574b8
    register char *sp;
Packit f574b8
Packit f574b8
    if (!*sub)
Packit f574b8
	return buf;
Packit f574b8
    while (*buf) {
Packit f574b8
	bp = buf;
Packit f574b8
	sp = sub;
Packit f574b8
	do {
Packit f574b8
	    if (!*sp)
Packit f574b8
		return buf;
Packit f574b8
	} while (*bp++ == *sp++);
Packit f574b8
	buf += 1;
Packit f574b8
    }
Packit f574b8
    return 0;
Packit f574b8
}