xref: /csrg-svn/lib/libc/string/memchr.c (revision 46144)
141949Sbostic /*-
241949Sbostic  * Copyright (c) 1990 The Regents of the University of California.
334479Sbostic  * 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*46144Sbostic static char sccsid[] = "@(#)memchr.c	5.6 (Berkeley) 01/26/91";
1334479Sbostic #endif /* LIBC_SCCS and not lint */
1424195Skre 
15*46144Sbostic #include <sys/cdefs.h>
1641949Sbostic #include <string.h>
1741949Sbostic 
1841949Sbostic void *
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