diff options
-rw-r--r-- | sys/lib/libkern/arch/alpha/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/arm32/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/i386/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/i386/memchr.S | 27 | ||||
-rw-r--r-- | sys/lib/libkern/arch/m68k/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/mips/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/ns32k/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/ns32k/memchr.S | 26 | ||||
-rw-r--r-- | sys/lib/libkern/arch/powerpc/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/sparc/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/arch/vax/Makefile.inc | 3 | ||||
-rw-r--r-- | sys/lib/libkern/memchr.c | 66 |
12 files changed, 137 insertions, 9 deletions
diff --git a/sys/lib/libkern/arch/alpha/Makefile.inc b/sys/lib/libkern/arch/alpha/Makefile.inc index ce0e0bcf1ba..22ee7218ea2 100644 --- a/sys/lib/libkern/arch/alpha/Makefile.inc +++ b/sys/lib/libkern/arch/alpha/Makefile.inc @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.7 1997/05/05 14:31:43 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.8 1997/11/04 19:08:01 chuck Exp $ # $NetBSD: Makefile.inc,v 1.9 1996/08/27 00:44:24 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c htonl.S htons.S ntohl.S ntohs.S \ random.c strncasecmp.c diff --git a/sys/lib/libkern/arch/arm32/Makefile.inc b/sys/lib/libkern/arch/arm32/Makefile.inc index af5cd572ac9..7e5d52920f5 100644 --- a/sys/lib/libkern/arch/arm32/Makefile.inc +++ b/sys/lib/libkern/arch/arm32/Makefile.inc @@ -1,6 +1,7 @@ -# $Id: Makefile.inc,v 1.1 1996/04/21 22:27:47 deraadt Exp $ +# $Id: Makefile.inc,v 1.2 1997/11/04 19:08:04 chuck Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \ div.S random.c strncasecmp.c diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc index 857134d5146..e048a85a5de 100644 --- a/sys/lib/libkern/arch/i386/Makefile.inc +++ b/sys/lib/libkern/arch/i386/Makefile.inc @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.4 1996/04/21 22:27:52 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.5 1997/11/04 19:08:05 chuck Exp $ # $NetBSD: Makefile.inc,v 1.10 1996/04/13 01:17:41 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.S \ bcmp.S ffs.S memset.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \ strncpy.c scanc.S skpc.S locc.S htonl.S htons.S ntohl.S ntohs.S \ strncasecmp.c diff --git a/sys/lib/libkern/arch/i386/memchr.S b/sys/lib/libkern/arch/i386/memchr.S new file mode 100644 index 00000000000..43f7a91e0a1 --- /dev/null +++ b/sys/lib/libkern/arch/i386/memchr.S @@ -0,0 +1,27 @@ +/* $OpenBSD: memchr.S,v 1.1 1997/11/04 19:08:06 chuck Exp $ */ + +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + */ + +#include <machine/asm.h> + +ENTRY(memchr) + pushl %edi + movl 8(%esp),%edi /* string address */ + movl 12(%esp),%eax /* set character to search for */ + movl 16(%esp),%ecx /* set length of search */ + testl %ecx,%ecx /* test for len == 0 */ + jz L1 + cld /* set search forward */ + repne /* search! */ + scasb + jne L1 /* scan failed, return null */ + leal -1(%edi),%eax /* adjust result of scan */ + popl %edi + ret + .align 2,0x90 +L1: xorl %eax,%eax + popl %edi + ret diff --git a/sys/lib/libkern/arch/m68k/Makefile.inc b/sys/lib/libkern/arch/m68k/Makefile.inc index 643e746f3c1..854cdc57e8a 100644 --- a/sys/lib/libkern/arch/m68k/Makefile.inc +++ b/sys/lib/libkern/arch/m68k/Makefile.inc @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.3 1996/05/01 15:12:28 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:08 chuck Exp $ # $NetBSD: Makefile.inc,v 1.7 1996/04/18 01:53:04 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.S \ strncpy.S htonl.S htons.S ntohl.S ntohs.S scanc.S skpc.S locc.S \ strncasecmp.c diff --git a/sys/lib/libkern/arch/mips/Makefile.inc b/sys/lib/libkern/arch/mips/Makefile.inc index 26665e5e1d5..d60ae259ebb 100644 --- a/sys/lib/libkern/arch/mips/Makefile.inc +++ b/sys/lib/libkern/arch/mips/Makefile.inc @@ -1,9 +1,10 @@ -# $OpenBSD: Makefile.inc,v 1.4 1996/05/15 08:24:15 pefo Exp $ +# $OpenBSD: Makefile.inc,v 1.5 1997/11/04 19:08:10 chuck Exp $ # $NetBSD: Makefile.inc,v 1.4 1996/04/13 01:17:46 cgd Exp $ # # There are likely more that we will notice when we go native SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.S bcopy.S bzero.S strcat.c strcmp.c strcpy.c ffs.S htonl.S \ htons.S strcmp.S strlen.S strncmp.c random.c scanc.c skpc.c strncpy.c \ strncasecmp.c diff --git a/sys/lib/libkern/arch/ns32k/Makefile.inc b/sys/lib/libkern/arch/ns32k/Makefile.inc index 67162a67186..d55cdd2c4de 100644 --- a/sys/lib/libkern/arch/ns32k/Makefile.inc +++ b/sys/lib/libkern/arch/ns32k/Makefile.inc @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.3 1996/04/21 22:27:58 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:11 chuck Exp $ # $NetBSD: Makefile.inc,v 1.7 1996/04/13 01:17:50 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.S \ bcmp.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \ scanc.c skpc.c locc.c strncasecmp.c \ htonl.S htons.S ntohl.S ntohs.S diff --git a/sys/lib/libkern/arch/ns32k/memchr.S b/sys/lib/libkern/arch/ns32k/memchr.S new file mode 100644 index 00000000000..ce1c105a232 --- /dev/null +++ b/sys/lib/libkern/arch/ns32k/memchr.S @@ -0,0 +1,26 @@ +/* $OpenBSD: memchr.S,v 1.1 1997/11/04 19:08:13 chuck Exp $ */ + +/* + * Written by Matthias Pfaller, 1996 + * Public domain. + */ + +#include <machine/asm.h> + + +/* + * void * + * memchr (const void *b, int c, size_t len) + * locate the first occurrence of c in string b. + */ + +ENTRY(memchr) + enter [r4],0 + movd B_ARG2,r0 + movb B_ARG1,r4 + movd B_ARG0,r1 + skpsb u + bfc 0f + movd r1,r0 +0: exit [r4] + ret 0 diff --git a/sys/lib/libkern/arch/powerpc/Makefile.inc b/sys/lib/libkern/arch/powerpc/Makefile.inc index d87436e87ae..42f058ef760 100644 --- a/sys/lib/libkern/arch/powerpc/Makefile.inc +++ b/sys/lib/libkern/arch/powerpc/Makefile.inc @@ -1,10 +1,11 @@ -# $OpenBSD: Makefile.inc,v 1.2 1996/12/28 06:17:46 rahnds Exp $ +# $OpenBSD: Makefile.inc,v 1.3 1997/11/04 19:08:15 chuck Exp $ # $NetBSD: Makefile.inc,v 1.6 1994/10/26 06:39:03 cgd Exp $ CFLAGS += -D_KERNEL SRCS+= __main.c __eabi.c \ imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c locc.c htonl.c htons.c ntohl.c ntohs.c \ memcpy.c random.c diff --git a/sys/lib/libkern/arch/sparc/Makefile.inc b/sys/lib/libkern/arch/sparc/Makefile.inc index 2fe78069580..7f79c087380 100644 --- a/sys/lib/libkern/arch/sparc/Makefile.inc +++ b/sys/lib/libkern/arch/sparc/Makefile.inc @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.3 1996/05/01 15:17:31 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:16 chuck Exp $ # $NetBSD: Makefile.inc,v 1.12 1996/04/23 23:05:22 christos Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlen.S strncmp.c \ strncpy.c htonl.S htons.S ntohl.S ntohs.S scanc.c skpc.c \ strncasecmp.c diff --git a/sys/lib/libkern/arch/vax/Makefile.inc b/sys/lib/libkern/arch/vax/Makefile.inc index 1741e47144d..57949c7e78a 100644 --- a/sys/lib/libkern/arch/vax/Makefile.inc +++ b/sys/lib/libkern/arch/vax/Makefile.inc @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.3 1997/01/14 14:45:42 maja Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1997/11/04 19:08:19 chuck Exp $ # $NetBSD: Makefile.inc,v 1.2 1996/04/13 01:17:58 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + memchr.c \ strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c strncasecmp.c diff --git a/sys/lib/libkern/memchr.c b/sys/lib/libkern/memchr.c new file mode 100644 index 00000000000..e5553d96693 --- /dev/null +++ b/sys/lib/libkern/memchr.c @@ -0,0 +1,66 @@ +/* $OpenBSD: memchr.c,v 1.1 1997/11/04 19:07:58 chuck Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 *sccsid = "from: @(#)memchr.c 5.6 (Berkeley) 1/26/91";*/ +static char *rcsid = "$NetBSD: memchr.c,v 1.2 1997/10/24 18:10:30 mjacob Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#ifndef _KERNEL +#include <string.h> +#else +#include <lib/libkern/libkern.h> +#define NULL ((char *)0) +#endif + +void * +memchr(s, c, n) + const void *s; + register unsigned char c; + register size_t n; +{ + if (n != 0) { + register const unsigned char *p = s; + + do { + if (*p++ == c) + return ((void *)(p - 1)); + } while (--n != 0); + } + return (NULL); +} |