2006-03-20 Thomas Koenig <Thomas.Koenig@online.de>
[official-gcc.git] / libiberty / memchr.c
blob451f817d3203fdfe420d2caee873619ede70bea7
1 /*
3 @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, size_t @var{n})
5 This function searches memory starting at @code{*@var{s}} for the
6 character @var{c}. The search only ends with the first occurrence of
7 @var{c}, or after @var{length} characters; in particular, a null
8 character does not terminate the search. If the character @var{c} is
9 found within @var{length} characters of @code{*@var{s}}, a pointer
10 to the character is returned. If @var{c} is not found, then @code{NULL} is
11 returned.
13 @end deftypefn
17 #include <ansidecl.h>
18 #include <stddef.h>
20 PTR
21 memchr (register const PTR src_void, int c, size_t length)
23 const unsigned char *src = (const unsigned char *)src_void;
25 while (length-- > 0)
27 if (*src == c)
28 return (PTR)src;
29 src++;
31 return NULL;