diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-06 01:12:06 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-06 01:12:06 +0000 |
commit | 876dba3f493f80a269822b189c650bf907295735 (patch) | |
tree | 971d3c3ce19576e5987b335eba59a96af6324d1f /sys/lib/libkern | |
parent | c7bd171a110dc759928d58a928869b7e355969c2 (diff) |
add back strchr/strrchr; from dhartmei
Diffstat (limited to 'sys/lib/libkern')
-rw-r--r-- | sys/lib/libkern/Makefile | 4 | ||||
-rw-r--r-- | sys/lib/libkern/libkern.h | 4 | ||||
-rw-r--r-- | sys/lib/libkern/strchr.c | 67 |
3 files changed, 72 insertions, 3 deletions
diff --git a/sys/lib/libkern/Makefile b/sys/lib/libkern/Makefile index ccb61613f9c..c198b3539c0 100644 --- a/sys/lib/libkern/Makefile +++ b/sys/lib/libkern/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2004/02/03 10:47:19 mickey Exp $ +# $OpenBSD: Makefile,v 1.16 2004/05/06 01:12:05 deraadt Exp $ # $NetBSD: Makefile,v 1.31 1996/08/10 04:01:31 mycroft Exp $ LIB= kern @@ -25,7 +25,7 @@ SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \ .endif # Other stuff -SRCS+= md5.c getsn.c srandom.c bcd.c +SRCS+= md5.c getsn.c srandom.c bcd.c strchr.c # Files to clean up CLEANFILES+= lib${LIB}.o lib${LIB}.po diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index f154dc551db..1acf6bf8775 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libkern.h,v 1.19 2003/06/23 21:02:27 millert Exp $ */ +/* $OpenBSD: libkern.h,v 1.20 2004/05/06 01:12:05 deraadt Exp $ */ /* $NetBSD: libkern.h,v 1.7 1996/03/14 18:52:08 christos Exp $ */ /*- @@ -167,6 +167,8 @@ int strcmp(const char *, const char *); int strncmp(const char *, const char *, size_t); int strncasecmp(const char *, const char *, size_t); int getsn(char *, int); +char *strchr(const char *, int); +char *strrchr(const char *, int); extern u_int8_t const __bcd2bin[], __bin2bcd[]; #define bcd2bin(b) (__bcd2bin[(b)&0xff]) diff --git a/sys/lib/libkern/strchr.c b/sys/lib/libkern/strchr.c new file mode 100644 index 00000000000..d4ede9b8e9d --- /dev/null +++ b/sys/lib/libkern/strchr.c @@ -0,0 +1,67 @@ +/* $OpenBSD: strchr.c,v 1.3 2004/05/06 01:12:05 deraadt Exp $ */ + +/* + * Copyright (c) 2004 Daniel Hartmeier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strchr.c,v 1.3 2004/05/06 01:12:05 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include <string.h> +#else +#include <lib/libkern/libkern.h> +#define NULL ((char *)0) +#endif + +char * +strchr(const char *s, int c) +{ + while (*s) { + if (*s == c) + return ((char *)s); + s++; + } + return (NULL); +} + +char * +strrchr(const char *s, int c) +{ + char *t = NULL; + + while (*s) { + if (*s == c) + t = (char *)s; + s++; + } + return (t); +} |