X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fwchar%2Fwmemmove.c;fp=functions%2Fwchar%2Fwmemmove.c;h=e8d6075936b031a1e239828f1614631b126bcc7f;hb=14b5b78e19a79f590233caee7848e7cb19084088;hp=0000000000000000000000000000000000000000;hpb=41777e3d5dc655f59a8c3bcd071639e6878e853a;p=pdclib diff --git a/functions/wchar/wmemmove.c b/functions/wchar/wmemmove.c new file mode 100644 index 0000000..e8d6075 --- /dev/null +++ b/functions/wchar/wmemmove.c @@ -0,0 +1,49 @@ +/* wmemmove( wchar_t *, const wchar_t *, size_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +wchar_t * wmemmove( wchar_t * dest, const wchar_t * src, size_t n ) +{ + wchar_t* rv = dest; + if ( dest <= src ) + { + while ( n-- ) + { + *dest++ = *src++; + } + } + else + { + src += n; + dest += n; + while ( n-- ) + { + *--dest = *--src; + } + } + return rv; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + wchar_t s[] = L"xxxxabcde"; + TESTCASE( wmemmove( s, s + 4, 5 ) == s ); + TESTCASE( s[0] == L'a' ); + TESTCASE( s[4] == L'e' ); + TESTCASE( s[5] == L'b' ); + TESTCASE( wmemmove( s + 4, s, 5 ) == s + 4 ); + TESTCASE( s[4] == L'a' ); + return TEST_RESULTS; +} +#endif