[hackers] [scc] [libc] Add memchr() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 08:47:29 +0100 (CET)

commit 5623808ee73aea1ceffcf3503def2ec3f4773e1a
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Feb 17 08:47:08 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Feb 17 08:47:08 2017 +0100

    [libc] Add memchr()

diff --git a/libc/src/Makefile b/libc/src/Makefile
index 9b9564b..3425b29 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -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 memcmp.o
+ memset.o memcpy.o memmove.o memcmp.o memchr.o
 
 all: libc.a
 
diff --git a/libc/src/memchr.c b/libc/src/memchr.c
new file mode 100644
index 0000000..3f44e90
--- /dev/null
+++ b/libc/src/memchr.c
_AT_@ -0,0 +1,13 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+void *
+memchr(const void *s, int c, size_t n)
+{
+ unsigned char *bp = (char *) s;
+
+ while (n > 0 && *bp++ != c)
+ --n;
+ return (n == 0) ? NULL : bp-1;
+}
Received on Fri Feb 17 2017 - 08:47:29 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 08:48:27 CET