summaryrefslogtreecommitdiffhomepage
path: root/src/string/ntapi_tt_aligned_block_memset.c
blob: 2be00a7d7120f95bf551dfae971e7960e3ad545c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include "ntapi_impl.h"

void * __cdecl __ntapi_tt_aligned_block_memset(
	__in	void *		block,
	__in	uintptr_t	val,
	__in	size_t		bytes)
{
	uintptr_t * ptr = (uintptr_t *)block;

	for (bytes/=sizeof(uintptr_t); bytes; bytes--)
		*ptr++=val;

	return block;
}

void * __cdecl __ntapi_tt_generic_memset(
	__in	void *		dst,
	__in	uintptr_t	val,
	__in	size_t		bytes)
{
	char	c;
	char *	ch;
	size_t	i;
	size_t	abytes;

	if (!bytes)
		return dst;

	else if (!(bytes % sizeof(size_t))
			&& (!(uintptr_t)dst % sizeof(size_t)))
		return __ntapi_tt_aligned_block_memset(
			dst,val,bytes);

	c = (char)val;
	for (i=0; i<sizeof(size_t); i++, val <<= 8)
		val += c;

	for (ch=(char *)dst; (size_t)ch % sizeof(size_t); ch++, bytes--)
		*ch = c;

	abytes = bytes / sizeof(size_t) * sizeof(size_t);
	__ntapi_tt_aligned_block_memset(ch,val,abytes);

	bytes -= abytes;
	ch += abytes;

	for (; bytes; ch++, bytes--)
		*ch = c;

	return dst;
}