summaryrefslogtreecommitdiff
path: root/src/stem/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stem/lib')
-rw-r--r--src/stem/lib/stdlib.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/stem/lib/stdlib.c b/src/stem/lib/stdlib.c
index 904126e..f4ebd33 100644
--- a/src/stem/lib/stdlib.c
+++ b/src/stem/lib/stdlib.c
@@ -1,12 +1,19 @@
#include "stdlib.h"
-void *memcpy(void *dest, const void *src, int count) {
- int i;
- uint8_t *d = (uint8_t*)dest, *s = (uint8_t*)src;
- for (i = 0; i < count; i++) {
+void *memcpy(void *vd, const void *vs, int count) {
+ uint8_t *dest = vd, *src = vs;
+ uint32_t f = count % 4, n = count / 4, i;
+ const uint32_t* s = (uint32_t*)src;
+ uint32_t* d = (uint32_t*)dest;
+ for (i = 0; i < n; i++) {
d[i] = s[i];
}
- return dest;
+ if (f != 0) {
+ for (i = count - f; i < count; i++) {
+ dest[i] = src[i];
+ }
+ }
+ return vd;
}
uint8_t *memset(uint8_t *dest, uint8_t val, int count) {
@@ -14,6 +21,7 @@ uint8_t *memset(uint8_t *dest, uint8_t val, int count) {
for (i = 0; i < count; i++) {
dest[i] = val;
}
+ return dest;
}
uint16_t *memsetw(uint16_t *dest, uint16_t val, int count) {