scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 92efbe7e846d7326ffbe076a99fb682172039261
parent 4b31904c19ede644b5657f46b5823faf9e2bcf09
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 17 Feb 2017 08:40:40 +0100

[libc] Add memcmp()

Diffstat:
Mlibc/src/Makefile | 2+-
Alibc/src/memcmp.c | 13+++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libc/src/Makefile b/libc/src/Makefile @@ -3,7 +3,7 @@ LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \ strrchr.o strcat.o strncpy.o strncat.o \ - memset.o memcpy.o memmove.o + memset.o memcpy.o memmove.o memcmp.o all: libc.a diff --git a/libc/src/memcmp.c b/libc/src/memcmp.c @@ -0,0 +1,13 @@ +/* See LICENSE file for copyright and license details. */ + +#include <string.h> + +int +memcmp(const void *s1, const void *s2, size_t n) +{ + char *s = (char *) s1, *t = (char *) s2; + + while (n > 0 && *s++ != *t++) + --n; + return n != 0; +}