198b9484cSchristos /*
298b9484cSchristos
398b9484cSchristos @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @
498b9484cSchristos size_t @var{n})
598b9484cSchristos
698b9484cSchristos This function searches memory starting at @code{*@var{s}} for the
798b9484cSchristos character @var{c}. The search only ends with the first occurrence of
898b9484cSchristos @var{c}, or after @var{length} characters; in particular, a null
998b9484cSchristos character does not terminate the search. If the character @var{c} is
1098b9484cSchristos found within @var{length} characters of @code{*@var{s}}, a pointer
1198b9484cSchristos to the character is returned. If @var{c} is not found, then @code{NULL} is
1298b9484cSchristos returned.
1398b9484cSchristos
1498b9484cSchristos @end deftypefn
1598b9484cSchristos
1698b9484cSchristos */
1798b9484cSchristos
1898b9484cSchristos #include <ansidecl.h>
1998b9484cSchristos #include <stddef.h>
2098b9484cSchristos
21*4b169a6bSchristos void *
memchr(register const void * src_void,int c,size_t length)22*4b169a6bSchristos memchr (register const void *src_void, int c, size_t length)
2398b9484cSchristos {
2498b9484cSchristos const unsigned char *src = (const unsigned char *)src_void;
2598b9484cSchristos
2698b9484cSchristos while (length-- > 0)
2798b9484cSchristos {
2898b9484cSchristos if (*src == c)
29*4b169a6bSchristos return (void *)src;
3098b9484cSchristos src++;
3198b9484cSchristos }
3298b9484cSchristos return NULL;
3398b9484cSchristos }
34