my previous version was wrong; this one is right
[unix-history] / usr / src / lib / libc / string / memchr.c
CommitLineData
b08ee90a
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
317e5946
KB
3 * All rights reserved.
4 *
b08ee90a
KB
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * %sccs.include.redist.c%
3fd49469
RE
9 */
10
2ce81398 11#if defined(LIBC_SCCS) && !defined(lint)
a64329b4 12static char sccsid[] = "@(#)memchr.c 5.6 (Berkeley) %G%";
317e5946 13#endif /* LIBC_SCCS and not lint */
3fd49469 14
a64329b4 15#include <sys/cdefs.h>
b08ee90a 16#include <string.h>
b08ee90a
KB
17
18void *
3fd49469 19memchr(s, c, n)
b08ee90a
KB
20 const void *s;
21 register unsigned char c;
22 register size_t n;
3fd49469 23{
b08ee90a
KB
24 if (n != 0) {
25 register const unsigned char *p = s;
26
27 do {
28 if (*p++ == c)
29 return ((void *)(p - 1));
30 } while (--n != 0);
31 }
32 return (NULL);
3fd49469 33}