Back to index

cell-binutils  2.17cvs20070401
memchr.c
Go to the documentation of this file.
00001 /*
00002 
00003 @deftypefn Supplemental void* memchr (const void *@var{s}, int @var{c}, size_t @var{n})
00004 
00005 This function searches memory starting at @code{*@var{s}} for the
00006 character @var{c}.  The search only ends with the first occurrence of
00007 @var{c}, or after @var{length} characters; in particular, a null
00008 character does not terminate the search.  If the character @var{c} is
00009 found within @var{length} characters of @code{*@var{s}}, a pointer
00010 to the character is returned.  If @var{c} is not found, then @code{NULL} is
00011 returned.
00012 
00013 @end deftypefn
00014 
00015 */
00016 
00017 #include <ansidecl.h>
00018 #include <stddef.h>
00019 
00020 PTR
00021 memchr (register const PTR src_void, int c, size_t length)
00022 {
00023   const unsigned char *src = (const unsigned char *)src_void;
00024   
00025   while (length-- > 0)
00026   {
00027     if (*src == c)
00028      return (PTR)src;
00029     src++;
00030   }
00031   return NULL;
00032 }