memchr.c revision 60484
133965Sjdp/* 233965SjdpFUNCTION 333965Sjdp <<memchr>>---find character in memory 433965Sjdp 533965SjdpINDEX 633965Sjdp memchr 733965Sjdp 833965SjdpANSI_SYNOPSIS 933965Sjdp #include <string.h> 1033965Sjdp void *memchr(const void *<[src]>, int <[c]>, size_t <[length]>); 1133965Sjdp 1233965SjdpTRAD_SYNOPSIS 1333965Sjdp #include <string.h> 1433965Sjdp void *memchr(<[src]>, <[c]>, <[length]>) 1533965Sjdp void *<[src]>; 1633965Sjdp void *<[c]>; 1733965Sjdp size_t <[length]>; 1833965Sjdp 1933965SjdpDESCRIPTION 2033965Sjdp This function searches memory starting at <<*<[src]>>> for the 2133965Sjdp character <[c]>. The search only ends with the first 2233965Sjdp occurrence of <[c]>, or after <[length]> characters; in 2333965Sjdp particular, <<NULL>> does not terminate the search. 2433965Sjdp 2533965SjdpRETURNS 2633965Sjdp If the character <[c]> is found within <[length]> characters 2733965Sjdp of <<*<[src]>>>, a pointer to the character is returned. If 2833965Sjdp <[c]> is not found, then <<NULL>> is returned. 2933965Sjdp 3033965SjdpPORTABILITY 3133965Sjdp<<memchr>> requires no supporting OS subroutines. 3233965Sjdp 3333965SjdpQUICKREF 3433965Sjdp memchr ansi pure 3533965Sjdp 3633965Sjdp*/ 3733965Sjdp 3833965Sjdp#include <ansidecl.h> 3933965Sjdp#ifdef __STDC__ 4033965Sjdp#include <stddef.h> 4133965Sjdp#else 4233965Sjdp#define size_t unsigned long 4333965Sjdp#endif 4433965Sjdp 4533965SjdpPTR 4633965Sjdpmemchr (src_void, c, length) 4760484Sobrien register const PTR src_void; 4833965Sjdp int c; 4933965Sjdp size_t length; 5033965Sjdp{ 5160484Sobrien const unsigned char *src = (const unsigned char *)src_void; 5233965Sjdp 5333965Sjdp while (--length >= 0) 5433965Sjdp { 5533965Sjdp if (*src == c) 5633965Sjdp return (PTR)src; 5733965Sjdp src++; 5833965Sjdp } 5933965Sjdp return NULL; 6033965Sjdp} 61