X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fmemmove.c;h=7a1cf7a29d90aa7a35f643be51a50ab1d2d7d0b2;hb=8c7d580ffac32921f34f4d254cf36cf872dafc7f;hp=9ecce5db20fa32741d4ab4164fa6214a38d3dde9;hpb=dcc8a8e99f69e090a03b7b868443addbc0817820;p=pdclib.old diff --git a/functions/string/memmove.c b/functions/string/memmove.c index 9ecce5d..7a1cf7a 100644 --- a/functions/string/memmove.c +++ b/functions/string/memmove.c @@ -5,4 +5,27 @@ // This code is Public Domain. Use, modify, and redistribute at will. // ---------------------------------------------------------------------------- -void * memmove( void * s1, const void * s2, size_t n ) { /* TODO */ }; +#include + +void * memmove( void * dest, const void * src, size_t n ) +{ + const char * src_p = (const char *) src; + char * dest_p = (char *) dest; + if ( dest_p < src_p ) + { + while ( n-- ) + { + *dest_p++ = *src_p++; + } + } + else + { + src_p += n; + dest_p += n; + while ( n-- ) + { + *dest_p-- = *src_p--; + } + } + return dest; +}