]> pd.if.org Git - pdclib/blobdiff - functions/string/strncmp.c
Reviewed.
[pdclib] / functions / string / strncmp.c
index d0434a54f3b53f38747b51fbd7c461899883de14..b6a98cecf77caa278aa6204691ca314168678bce 100644 (file)
@@ -5,4 +5,18 @@
 // This code is Public Domain. Use, modify, and redistribute at will.
 // ----------------------------------------------------------------------------
 
-int strncmp( const char * s1, const char * s2, size_t n ) { /* TODO */ };
+#include <__size_t.h>
+
+int strncmp( const char * src_1, const char * src_2, size_t n )
+{
+    while ( ( n-- != 0 ) && ( *src_1 == *src_2 ) )
+    {
+        ++src_1;
+        ++src_2;
+    }
+    if ( ( n == 0 ) )
+    {
+        return 0;
+    }
+    return ( *src_1 - *src_2 );
+}