scc

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

commit 714865e3490220bae41784c95e0c99c9fcff11d7
parent 7def427f50ce226527e40191d38057ad68856570
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 21 Feb 2017 17:48:50 +0100

[libc] Add strncmp

Diffstat:
libc/src/Makefile | 2+-
libc/src/strncmp.c | 11+++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libc/src/Makefile b/libc/src/Makefile @@ -2,7 +2,7 @@ .POSIX: LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \ - strrchr.o strcat.o strncpy.o strncat.o strcoll.o \ + strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \ strxfrm.o strtok.o \ memset.o memcpy.o memmove.o memcmp.o memchr.o \ isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \ diff --git a/libc/src/strncmp.c b/libc/src/strncmp.c @@ -0,0 +1,11 @@ +/* See LICENSE file for copyright and license details. */ + +#include <string.h> + +int +strncmp(const char *s1, const char *s2, size_t n) +{ + for (; n && *s1 && *s2 && *s1 != *s2; --n, ++s1, ++s2); + /* nothing */; + return n ? (*(unsigned char *)s1 - *(unsigned char *)s2) : 0; +}