]> pd.if.org Git - pdclib/blobdiff - functions/string/memmove.c
Added dummy test drivers to each *.c file, and target 'test' to Makefile.
[pdclib] / functions / string / memmove.c
index 9ecce5db20fa32741d4ab4164fa6214a38d3dde9..38db9d94a2e4d3dad1af059c2b7edeab4aa55d1f 100644 (file)
@@ -1,8 +1,43 @@
-// ----------------------------------------------------------------------------
-// $Id$
-// ----------------------------------------------------------------------------
-// Public Domain C Library - http://pdclib.sourceforge.net
-// This code is Public Domain. Use, modify, and redistribute at will.
-// ----------------------------------------------------------------------------
-
-void * memmove( void * s1, const void * s2, size_t n ) { /* TODO */ };
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* memmove( void *, const void *, 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 <string.h>
+
+void * memmove( void * s1, const void * s2, size_t n )
+{
+    char * dest = (char *) s1;
+    const char * src = (const char *) s2;
+    if ( dest < src )
+    {
+        while ( n-- )
+        {
+            *dest++ = *src++;
+        }
+    }
+    else
+    {
+        src += n;
+        dest += n;
+        while ( n-- )
+        {
+            *dest-- = *src--;
+        }
+    }
+    return s1;
+}
+
+#warning Test driver missing.
+
+#ifdef TEST
+int main()
+{
+    return 0;
+}
+#endif