mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[liba] Add memmove to string.h
Change-Id: I99b412dc7404e2711dbf7753f0d619694dee3d19
This commit is contained in:
committed by
Romain Goyet
parent
301e0a7891
commit
2898ec916c
@@ -12,6 +12,7 @@ objs += $(addprefix liba/src/, \
|
||||
isinff.o \
|
||||
malloc.o \
|
||||
memcpy.o \
|
||||
memmove.o \
|
||||
memset.o \
|
||||
strcmp.o \
|
||||
strlcpy.o \
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
LIBA_BEGIN_DECLS
|
||||
|
||||
void * memcpy(void * dst, const void * src, size_t n);
|
||||
void * memmove(void * dst, const void * src, size_t n);
|
||||
void * memset(void * b, int c, size_t len);
|
||||
size_t strlen(const char * s);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
|
||||
21
liba/src/memmove.c
Normal file
21
liba/src/memmove.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <string.h>
|
||||
|
||||
void * memmove(void * dst, const void * src, size_t n) {
|
||||
char * destination = (char *)dst;
|
||||
char * source = (char *)src;
|
||||
|
||||
if (source < destination && destination < source + n) {
|
||||
/* Copy backwards to avoid overwrites */
|
||||
source += n;
|
||||
destination += n;
|
||||
while (n--) {
|
||||
*--destination = *--source;
|
||||
}
|
||||
} else {
|
||||
while (n--) {
|
||||
*destination++ = *source++;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
Reference in New Issue
Block a user