X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrncmp.c;h=b6a98cecf77caa278aa6204691ca314168678bce;hb=19b4cc9a30c2ede7a0cd6c417b5f26851376b708;hp=d0434a54f3b53f38747b51fbd7c461899883de14;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec;p=pdclib 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 ); +}