testsuite, threads: fix LD_LIBRARY_PATH in 'tls-sepdebug.exp'
[binutils-gdb.git] / libiberty / memchr.c
blob7551b140b59e78055e81a0e71283fbc3cc477ff9
1 /*
3 @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @
4 size_t @var{n})
6 This function searches memory starting at @code{*@var{s}} for the
7 character @var{c}. The search only ends with the first occurrence of
8 @var{c}, or after @var{length} characters; in particular, a null
9 character does not terminate the search. If the character @var{c} is
10 found within @var{length} characters of @code{*@var{s}}, a pointer
11 to the character is returned. If @var{c} is not found, then @code{NULL} is
12 returned.
14 @end deftypefn
18 #include <ansidecl.h>
19 #include <stddef.h>
21 void *
22 memchr (register const void *src_void, int c, size_t length)
24 const unsigned char *src = (const unsigned char *)src_void;
26 while (length-- > 0)
28 if (*src == c)
29 return (void *)src;
30 src++;
32 return NULL;