]>
Commit | Line | Data |
---|---|---|
6599da04 | 1 | /* |
6599da04 | 2 | |
996c0cb0 RW |
3 | @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, @ |
4 | size_t @var{n}) | |
6599da04 | 5 | |
7f8fa05d | 6 | This function searches memory starting at @code{*@var{s}} for the |
aaa5f039 DD |
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 | |
7f8fa05d JM |
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 | |
aaa5f039 | 12 | returned. |
6599da04 | 13 | |
aaa5f039 | 14 | @end deftypefn |
6599da04 JM |
15 | |
16 | */ | |
17 | ||
18 | #include <ansidecl.h> | |
6599da04 | 19 | #include <stddef.h> |
6599da04 | 20 | |
50b009c5 ML |
21 | void * |
22 | memchr (register const void *src_void, int c, size_t length) | |
6599da04 | 23 | { |
11a0bb74 | 24 | const unsigned char *src = (const unsigned char *)src_void; |
6599da04 | 25 | |
27f66c0b | 26 | while (length-- > 0) |
6599da04 JM |
27 | { |
28 | if (*src == c) | |
50b009c5 | 29 | return (void *)src; |
6599da04 JM |
30 | src++; |
31 | } | |
32 | return NULL; | |
33 | } |