summaryrefslogtreecommitdiffhomepage
path: root/src/string/ntapi_tt_aligned_block_memset.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
committermidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
commitdd89bb8ad4fe184a34b5dbdda237e640fc82121b (patch)
tree5e80d2da35f5892f92be29f57982b2708e6bd99b /src/string/ntapi_tt_aligned_block_memset.c
parentdcdadc2702712fa750ed255ed1dfa354522797a0 (diff)
downloadntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2
ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz
entered advanced internal development stage.
Diffstat (limited to 'src/string/ntapi_tt_aligned_block_memset.c')
-rw-r--r--src/string/ntapi_tt_aligned_block_memset.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/string/ntapi_tt_aligned_block_memset.c b/src/string/ntapi_tt_aligned_block_memset.c
new file mode 100644
index 0000000..8e64360
--- /dev/null
+++ b/src/string/ntapi_tt_aligned_block_memset.c
@@ -0,0 +1,57 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013,2014,2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <psxtypes/psxtypes.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;
+ int 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;
+}