shithub: scc

Download patch

ref: 7a8639f8d538ae219209765bbbfa7a99ab086105
parent: 0eaa0e21ca1c958ca2ea372e2e785e7392a0818c
author: Quentin Rameau <quinq@fifth.space>
date: Tue Feb 21 12:48:50 EST 2017

[libc] Add strncmp

--- 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 \
--- /dev/null
+++ b/libc/src/strncmp.c
@@ -1,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;
+}