/****************************************************************************
 *
 * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/string/memchr.c,v $
 * $Date: 2005/11/16 03:15:42 $
 * $Revision: 1.2 $
 * $State: Exp $
 * $Author: joty $
 *
 ***************************************************************************/

#include <string.h>

void *
memchr (const void *s, int c_, size_t n)

{
  unsigned char *_s = (unsigned char *)(int) s;
  char c = (char) c_;

  while (n & 0x07)
    {
      n--;
      if (*_s++ == c)
	{
	ret:return ((void *) (--_s));
	}
    }
  n >>= 3;
  while (n)
    {
      n--;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
      if (*_s++ == c)
	goto ret;
    }

  return (0);
}
