xref: /csrg-svn/lib/libc/string/memchr.c (revision 41949)
1*41949Sbostic /*-
2*41949Sbostic  * Copyright (c) 1990 The Regents of the University of California.
334479Sbostic  * All rights reserved.
434479Sbostic  *
5*41949Sbostic  * This code is derived from software contributed to Berkeley by
6*41949Sbostic  * Chris Torek.
7*41949Sbostic  *
8*41949Sbostic  * %sccs.include.redist.c%
924195Skre  */
1024195Skre 
1126526Sdonn #if defined(LIBC_SCCS) && !defined(lint)
12*41949Sbostic static char sccsid[] = "@(#)memchr.c	5.5 (Berkeley) 05/15/90";
1334479Sbostic #endif /* LIBC_SCCS and not lint */
1424195Skre 
15*41949Sbostic #include <string.h>
16*41949Sbostic #include <sys/stdc.h>
17*41949Sbostic 
18*41949Sbostic void *
1924195Skre memchr(s, c, n)
20*41949Sbostic 	const void *s;
21*41949Sbostic 	register unsigned char c;
22*41949Sbostic 	register size_t n;
2324195Skre {
24*41949Sbostic 	if (n != 0) {
25*41949Sbostic 		register const unsigned char *p = s;
26*41949Sbostic 
27*41949Sbostic 		do {
28*41949Sbostic 			if (*p++ == c)
29*41949Sbostic 				return ((void *)(p - 1));
30*41949Sbostic 		} while (--n != 0);
31*41949Sbostic 	}
32*41949Sbostic 	return (NULL);
3324195Skre }
34