From f0a5c1029a4d9e5497fe457e38db8db7a021dc86 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Mon, 19 May 2008 10:05:18 +0000 Subject: [PATCH] Declare lsearch(3)/lfind(3), move them to libc and make them POSIX compliant. Obtained-from: FreeBSD --- include/search.h | 6 +- lib/libc/stdlib/Makefile.inc | 7 ++- lib/libcompat/4.3/lsearch.3 | 106 ----------------------------------- lib/libcompat/4.3/lsearch.c | 92 ------------------------------ lib/libcompat/Makefile | 7 +-- 5 files changed, 12 insertions(+), 206 deletions(-) delete mode 100644 lib/libcompat/4.3/lsearch.3 delete mode 100644 lib/libcompat/4.3/lsearch.c diff --git a/include/search.h b/include/search.h index f3f94cffaf..ccd7427d48 100644 --- a/include/search.h +++ b/include/search.h @@ -1,6 +1,6 @@ /* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $ */ /* $FreeBSD: src/include/search.h,v 1.3.2.1 2000/08/17 07:38:34 jhb Exp $ */ -/* $DragonFly: src/include/search.h,v 1.5 2003/11/15 19:28:42 asmodai Exp $ */ +/* $DragonFly: src/include/search.h,v 1.6 2008/05/19 10:05:18 corecode Exp $ */ /* * Written by J.T. Conklin @@ -45,6 +45,10 @@ __BEGIN_DECLS int hcreate (size_t); void hdestroy (void); ENTRY *hsearch (ENTRY, ACTION); +void *lfind(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *)); +void *lsearch(const void *, void *, size_t *, size_t, + int (*)(const void *, const void *)); void *tdelete (const void *, void **, int (*)(const void *, const void *)); void *tfind (const void *, void **, diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index a30f471d23..75b265c9f5 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -1,6 +1,6 @@ # from @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # $FreeBSD: src/lib/libc/stdlib/Makefile.inc,v 1.19.2.4 2001/10/02 11:15:38 ru Exp $ -# $DragonFly: src/lib/libc/stdlib/Makefile.inc,v 1.21 2008/01/25 23:24:31 swildner Exp $ +# $DragonFly: src/lib/libc/stdlib/Makefile.inc,v 1.22 2008/05/19 10:05:18 corecode Exp $ # machine-independent stdlib sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib ${.CURDIR}/../libc/stdlib @@ -8,7 +8,7 @@ MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c bsearch.c calloc.c div.c \ exit.c getenv.c getopt.c getopt_long.c getsubopt.c hcreate.c heapsort.c \ imaxabs.c imaxdiv.c \ - labs.c ldiv.c llabs.c lldiv.c malloc.c merge.c putenv.c \ + labs.c ldiv.c llabs.c lldiv.c lsearch.c malloc.c merge.c putenv.c \ qsort.c radixsort.c rand.c \ random.c reallocf.c realpath.c setenv.c strtod.c strtoimax.c strtol.c \ strtoll.c strtonum.c strtoq.c strtoul.c strtoull.c strtoumax.c \ @@ -23,7 +23,7 @@ MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c bsearch.c calloc.c d MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 hcreate.3 \ imaxabs.3 imaxdiv.3 \ - labs.3 ldiv.3 llabs.3 lldiv.3 malloc.3 memory.3 \ + labs.3 ldiv.3 llabs.3 lldiv.3 lsearch.3 malloc.3 memory.3 \ qsort.3 radixsort.3 rand.3 random.3 \ realpath.3 strtod.3 strtol.3 strtonum.3 strtoul.3 system.3 tsearch.3 @@ -32,6 +32,7 @@ MLINKS+=exit.3 _Exit.3 MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3 MLINKS+=getopt_long.3 getopt_long_only.3 MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3 +MLINKS+=lsearch.3 lfind.3 MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 realloc.3 malloc.3 reallocf.3 MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 MLINKS+=rand.3 rand_r.3 rand.3 srand.3 rand.3 sranddev.3 diff --git a/lib/libcompat/4.3/lsearch.3 b/lib/libcompat/4.3/lsearch.3 deleted file mode 100644 index 82b9ebf7b2..0000000000 --- a/lib/libcompat/4.3/lsearch.3 +++ /dev/null @@ -1,106 +0,0 @@ -.\" Copyright (c) 1989, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" 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. -.\" -.\" @(#)lsearch.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libcompat/4.3/lsearch.3,v 1.4.2.4 2001/12/17 10:08:29 ru Exp $ -.\" $DragonFly: src/lib/libcompat/4.3/Attic/lsearch.3,v 1.2 2003/06/17 04:26:48 dillon Exp $ -.\" -.Dd June 4, 1993 -.Dt LSEARCH 3 -.Os -.Sh NAME -.Nm lsearch , -.Nm lfind -.Nd linear searching routines -.Sh LIBRARY -.Lb libcompat -.Sh SYNOPSIS -.In sys/types.h -.Ft char * -.Fn lsearch "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" -.Ft char * -.Fn lfind "const void *key" "const void *base" "size_t *nelp" "size_t width" "int (*compar)(void *, void *)" -.Sh DESCRIPTION -.Bf -symbolic -This interface was obsolete before it was written. -.Ef -.Pp -The functions -.Fn lsearch , -and -.Fn lfind -provide basic linear searching functionality. -.Pp -.Fa Base -is the pointer to the beginning of an array. -The argument -.Fa nelp -is the current number of elements in the array, where each element -is -.Fa width -bytes long. -The -.Fa compar -function -is a comparison routine which is used to compare two elements. -It takes two arguments which point to the -.Fa key -object and to an array member, in that order, and must return an integer -less than, equivalent to, or greater than zero if the -.Fa key -object is considered, respectively, to be less than, equal to, or greater -than the array member. -.Pp -The -.Fn lsearch -and -.Fn lfind -functions -return a pointer into the array referenced by -.Fa base -where -.Fa key -is located. -If -.Fa key -does not exist, -.Fn lfind -will return a null pointer and -.Fn lsearch -will add it to the array. -When an element is added to the array by -.Fn lsearch -the location referenced by the argument -.Fa nelp -is incremented by one. -.Sh SEE ALSO -.Xr bsearch 3 , -.Xr db 3 diff --git a/lib/libcompat/4.3/lsearch.c b/lib/libcompat/4.3/lsearch.c deleted file mode 100644 index 7cd88f73e5..0000000000 --- a/lib/libcompat/4.3/lsearch.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Roger L. Snyder. - * - * 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. - * - * @(#)lsearch.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcompat/4.3/Attic/lsearch.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ - */ - -#include -#include -#include - -static char *linear_base(); - -char * -lsearch(key, base, nelp, width, compar) - char *key, *base; - u_int *nelp, width; - int (*compar)(); -{ - return(linear_base(key, base, nelp, width, compar, 1)); -} - -char * -lfind(key, base, nelp, width, compar) - char *key, *base; - u_int *nelp, width; - int (*compar)(); -{ - return(linear_base(key, base, nelp, width, compar, 0)); -} - -static char * -linear_base(key, base, nelp, width, compar, add_flag) - char *key, *base; - u_int *nelp, width; - int (*compar)(), add_flag; -{ - char *element, *end; - - end = base + *nelp * width; - for (element = base; element < end; element += width) - if (!compar(element, key)) /* key found */ - return(element); - - if (!add_flag) /* key not found */ - return(NULL); - - /* - * The UNIX System User's Manual, 1986 edition claims that - * a NULL pointer is returned by lsearch with errno set - * appropriately, if there is not enough room in the table - * to add a new item. This can't be done as none of these - * routines have any method of determining the size of the - * table. This comment was isn't in the 1986-87 System V - * manual. - */ - ++*nelp; - bcopy(key, end, (int)width); - return(end); -} diff --git a/lib/libcompat/Makefile b/lib/libcompat/Makefile index 9825e018f3..8092f523cc 100644 --- a/lib/libcompat/Makefile +++ b/lib/libcompat/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.1 (Berkeley) 6/4/93 # $FreeBSD: src/lib/libcompat/Makefile,v 1.19.2.1 2001/04/25 10:04:23 ru Exp $ -# $DragonFly: src/lib/libcompat/Makefile,v 1.2 2003/06/17 04:26:48 dillon Exp $ +# $DragonFly: src/lib/libcompat/Makefile,v 1.3 2008/05/19 10:05:18 corecode Exp $ LIB=compat CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS -I${.CURDIR}/../libc/locale @@ -24,17 +24,16 @@ MLINKS+=cftime.3 ascftime.3 # compat 4.3 sources # XXX MISSING: ecvt.c gcvt.c sibuf.c sobuf.c strout.c -SRCS+= cfree.c lsearch.c regex.c rexec.c +SRCS+= cfree.c regex.c rexec.c SRCS+= insque.c remque.c # XXX MISSING: ecvt.0 -MAN+= 4.3/cfree.3 4.3/insque.3 4.3/lsearch.3 4.3/re_comp.3 4.3/rexec.3 +MAN+= 4.3/cfree.3 4.3/insque.3 4.3/re_comp.3 4.3/rexec.3 # XXX MISSING: ecvt.3, so can't MLINK #MLINKS+=ecvt.3 fcvt.3 ecvt.3 gcvt.3 MLINKS+=insque.3 remque.3 MLINKS+=re_comp.3 re_exec.3 -MLINKS+=lsearch.3 lfind.3 # compat 4.4 sources SRCS+= cuserid.c -- 2.41.0