X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrncmp.c;h=b6a98cecf77caa278aa6204691ca314168678bce;hb=5f75278ec2ac5240da801193a7b0cf93cb02e461;hp=d0434a54f3b53f38747b51fbd7c461899883de14;hpb=dcc8a8e99f69e090a03b7b868443addbc0817820;p=pdclib.old diff --git a/functions/string/strncmp.c b/functions/string/strncmp.c index d0434a5..b6a98ce 100644 --- a/functions/string/strncmp.c +++ b/functions/string/strncmp.c @@ -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 ); +}