Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* |
252b5132 | 2 | |
39423523 | 3 | @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, size_t @var{n}) |
252b5132 | 4 | |
99b58139 | 5 | This function searches memory starting at @code{*@var{s}} for the |
39423523 DD |
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 | |
99b58139 DD |
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 | |
39423523 | 11 | returned. |
252b5132 | 12 | |
39423523 | 13 | @end deftypefn |
252b5132 RH |
14 | |
15 | */ | |
16 | ||
17 | #include <ansidecl.h> | |
7ec2fc6f | 18 | #ifdef ANSI_PROTOTYPES |
252b5132 RH |
19 | #include <stddef.h> |
20 | #else | |
21 | #define size_t unsigned long | |
22 | #endif | |
23 | ||
24 | PTR | |
25 | memchr (src_void, c, length) | |
26 | register const PTR src_void; | |
27 | int c; | |
28 | size_t length; | |
29 | { | |
30 | const unsigned char *src = (const unsigned char *)src_void; | |
31 | ||
30a1def2 | 32 | while (length-- > 0) |
252b5132 RH |
33 | { |
34 | if (*src == c) | |
35 | return (PTR)src; | |
36 | src++; | |
37 | } | |
38 | return NULL; | |
39 | } |