]> pd.if.org Git - pdclib/blobdiff - functions/string/memcmp.c
Added some of <string.h>.
[pdclib] / functions / string / memcmp.c
diff --git a/functions/string/memcmp.c b/functions/string/memcmp.c
new file mode 100644 (file)
index 0000000..d873c07
--- /dev/null
@@ -0,0 +1,27 @@
+/* $Id$ */
+
+/* Release $Name$ */
+
+/* memcmp( const 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>
+
+int memcmp( const void * s1, const void * s2, size_t n )
+{
+    const unsigned char * p1 = (const unsigned char *) s1;
+    const unsigned char * p2 = (const unsigned char *) s2;
+    while ( n-- )
+    {
+        if ( *p1 != *p2 )
+        {
+            return *p2 - *p1;
+        }
+        ++p1;
+        ++p2;
+    }
+    return 0;
+}