X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fmemcmp.c;fp=functions%2Fstring%2Fmemcmp.c;h=d873c07d140eb1ee781369ac84fb52bbe37d823f;hb=c2f1367984ba4153d892062759c3813020b65a9a;hp=0000000000000000000000000000000000000000;hpb=3220f577b186e04180acd7554a785c60dfb7ebb2;p=pdclib diff --git a/functions/string/memcmp.c b/functions/string/memcmp.c new file mode 100644 index 0000000..d873c07 --- /dev/null +++ b/functions/string/memcmp.c @@ -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 + +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; +}