Blame src/string/ntapi_tt_aligned_block_memset.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
766a63
#include "ntapi_impl.h"
dd89bb
dd89bb
void * __cdecl __ntapi_tt_aligned_block_memset(
dd89bb
	__in	void *		block,
dd89bb
	__in	uintptr_t	val,
dd89bb
	__in	size_t		bytes)
dd89bb
{
dd89bb
	uintptr_t * ptr = (uintptr_t *)block;
dd89bb
dd89bb
	for (bytes/=sizeof(uintptr_t); bytes; bytes--)
dd89bb
		*ptr++=val;
dd89bb
dd89bb
	return block;
dd89bb
}
dd89bb
dd89bb
void * __cdecl __ntapi_tt_generic_memset(
dd89bb
	__in	void *		dst,
dd89bb
	__in	uintptr_t	val,
dd89bb
	__in	size_t		bytes)
dd89bb
{
dd89bb
	char	c;
dd89bb
	char *	ch;
eed8dc
	size_t	i;
dd89bb
	size_t	abytes;
dd89bb
dd89bb
	if (!bytes)
dd89bb
		return dst;
dd89bb
dd89bb
	else if (!(bytes % sizeof(size_t))
dd89bb
			&& (!(uintptr_t)dst % sizeof(size_t)))
dd89bb
		return __ntapi_tt_aligned_block_memset(
dd89bb
			dst,val,bytes);
dd89bb
dd89bb
	c = (char)val;
dd89bb
	for (i=0; i
dd89bb
		val += c;
dd89bb
dd89bb
	for (ch=(char *)dst; (size_t)ch % sizeof(size_t); ch++, bytes--)
dd89bb
		*ch = c;
dd89bb
dd89bb
	abytes = bytes / sizeof(size_t) * sizeof(size_t);
dd89bb
	__ntapi_tt_aligned_block_memset(ch,val,abytes);
dd89bb
dd89bb
	bytes -= abytes;
dd89bb
	ch += abytes;
dd89bb
dd89bb
	for (; bytes; ch++, bytes--)
dd89bb
		*ch = c;
dd89bb
dd89bb
	return dst;
dd89bb
}