scc

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

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

[libc] Add memchr()

Diffstat:
Mlibc/src/Makefile | 2+-
Alibc/src/memchr.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 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 @@ -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; +}