/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#include <string.h>

/** @addtogroup string */
/** @{ */

/**
*	Locate the first occurance of a given byte in a memory region.
*
*	The function returns a pointer to the first occurance of the byte
*	\p c in the \p n bytes long memory area pointed by \p p. If the
*	memory area does not contain the character, then NULL is returned.
*	Note that the parameter \p c is \p int, not \p char. Only the lower 8
*	bits of the int value will be used, all the higher bits are simply
*	ignored.
*
*	@param	p		Pointer to the memory area
*	@param	c		The character to look for
*	@param	n		The size of the memory area
*	@return			Pointer to the first occurance of the character in the
*					string or NULL if the string does not contain the character
*/

void	*memchr( const void *p, int c, size_t n )
{
unsigned char	*s;

	for ( s = (unsigned char *) p, c &= 255 ; n-- ; )

		if ( *s++ == c ) return( s - 1 );

	return( NULL );
}

/** @} */

