xref: /csrg-svn/lib/libc/string/memchr.c (revision 61193)
141949Sbostic /*-
2*61193Sbostic  * Copyright (c) 1990, 1993
3*61193Sbostic  *	The Regents of the University of California.  All rights reserved.
434479Sbostic  *
541949Sbostic  * This code is derived from software contributed to Berkeley by
641949Sbostic  * Chris Torek.
741949Sbostic  *
841949Sbostic  * %sccs.include.redist.c%
924195Skre  */
1024195Skre 
1126526Sdonn #if defined(LIBC_SCCS) && !defined(lint)
12*61193Sbostic static char sccsid[] = "@(#)memchr.c	8.1 (Berkeley) 06/04/93";
1334479Sbostic #endif /* LIBC_SCCS and not lint */
1424195Skre 
1546144Sbostic #include <sys/cdefs.h>
1641949Sbostic #include <string.h>
1741949Sbostic 
1841949Sbostic void *
memchr(s,c,n)1924195Skre memchr(s, c, n)
2041949Sbostic 	const void *s;
2141949Sbostic 	register unsigned char c;
2241949Sbostic 	register size_t n;
2324195Skre {
2441949Sbostic 	if (n != 0) {
2541949Sbostic 		register const unsigned char *p = s;
2641949Sbostic 
2741949Sbostic 		do {
2841949Sbostic 			if (*p++ == c)
2941949Sbostic 				return ((void *)(p - 1));
3041949Sbostic 		} while (--n != 0);
3141949Sbostic 	}
3241949Sbostic 	return (NULL);
3324195Skre }
34