16c84d0b1SRobert Drehmel.\" 26c84d0b1SRobert Drehmel.\" Initial implementation: 36c84d0b1SRobert Drehmel.\" Copyright (c) 2002 Robert Drehmel 46c84d0b1SRobert Drehmel.\" All rights reserved. 56c84d0b1SRobert Drehmel.\" 66c84d0b1SRobert Drehmel.\" As long as the above copyright statement and this notice remain 76c84d0b1SRobert Drehmel.\" unchanged, you can do what ever you want with this file. 86c84d0b1SRobert Drehmel.\" 96c84d0b1SRobert Drehmel.\" $FreeBSD$ 106c84d0b1SRobert Drehmel.\" 116c84d0b1SRobert Drehmel.Dd October 11, 2002 126c84d0b1SRobert Drehmel.Dt LSEARCH 3 136c84d0b1SRobert Drehmel.Os 146c84d0b1SRobert Drehmel.Sh NAME 156c84d0b1SRobert Drehmel.Nm lsearch , 166c84d0b1SRobert Drehmel.Nm lfind 176c84d0b1SRobert Drehmel.Nd linear search and append 186c84d0b1SRobert Drehmel.Sh LIBRARY 196c84d0b1SRobert Drehmel.Lb libc 206c84d0b1SRobert Drehmel.Sh SYNOPSIS 216c84d0b1SRobert Drehmel.In search.h 22142de08dSRuslan Ermilov.Ft "void *" 23142de08dSRuslan Ermilov.Fo lsearch 24142de08dSRuslan Ermilov.Fa "const void *key" "void *base" "size_t *nelp" "size_t width" 25142de08dSRuslan Ermilov.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" 26142de08dSRuslan Ermilov.Fc 27142de08dSRuslan Ermilov.Ft "void *" 28142de08dSRuslan Ermilov.Fo lfind 29142de08dSRuslan Ermilov.Fa "const void *key" "const void *base" "size_t *nelp" "size_t width" 30142de08dSRuslan Ermilov.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]" 31142de08dSRuslan Ermilov.Fc 326c84d0b1SRobert Drehmel.Sh DESCRIPTION 336c84d0b1SRobert DrehmelThe 346c84d0b1SRobert Drehmel.Fn lsearch 356c84d0b1SRobert Drehmeland 366c84d0b1SRobert Drehmel.Fn lfind 376c84d0b1SRobert Drehmelfunctions walk linearly through an array and compare each element with 386c84d0b1SRobert Drehmelthe one to be sought using a supplied comparison function. 396c84d0b1SRobert Drehmel.Pp 402efeeba5SRuslan ErmilovThe 416c84d0b1SRobert Drehmel.Fa key 422efeeba5SRuslan Ermilovargument 436c84d0b1SRobert Drehmelpoints to an element that matches the one that is searched. 446c84d0b1SRobert DrehmelThe array's address in memory is denoted by the 456c84d0b1SRobert Drehmel.Fa base 466c84d0b1SRobert Drehmelargument. 47142de08dSRuslan ErmilovThe width of one element (i.e., the size as returned by 486c84d0b1SRobert Drehmel.Fn sizeof ) 496c84d0b1SRobert Drehmelis passed as the 506c84d0b1SRobert Drehmel.Fa width 516c84d0b1SRobert Drehmelargument. 526c84d0b1SRobert DrehmelThe number of valid elements contained in the array (not the number of 536c84d0b1SRobert Drehmelelements the array has space reserved for) is given in the integer pointed 546c84d0b1SRobert Drehmelto by 556c84d0b1SRobert Drehmel.Fa nelp . 566c84d0b1SRobert DrehmelThe 576c84d0b1SRobert Drehmel.Fa compar 586c84d0b1SRobert Drehmelargument points to a function which compares its two arguments and returns 59142de08dSRuslan Ermilovzero if they are matching, and non-zero otherwise. 606c84d0b1SRobert Drehmel.Pp 616c84d0b1SRobert DrehmelIf no matching element was found in the array, 626c84d0b1SRobert Drehmel.Fn lsearch 636c84d0b1SRobert Drehmelcopies 646c84d0b1SRobert Drehmel.Fa key 656c84d0b1SRobert Drehmelinto the position after the last element and increments the 666c84d0b1SRobert Drehmelinteger pointed to by 676c84d0b1SRobert Drehmel.Fa nelp . 686c84d0b1SRobert Drehmel.Sh RETURN VALUES 691fae73b1SRuslan ErmilovThe 706c84d0b1SRobert Drehmel.Fn lsearch 716c84d0b1SRobert Drehmeland 726c84d0b1SRobert Drehmel.Fn lfind 731fae73b1SRuslan Ermilovfunctions 746c84d0b1SRobert Drehmelreturn a pointer to the first element found. 756c84d0b1SRobert DrehmelIf no element was found, 766c84d0b1SRobert Drehmel.Fn lsearch 776c84d0b1SRobert Drehmelreturns a pointer to the newly added element, whereas 786c84d0b1SRobert Drehmel.Fn lfind 796c84d0b1SRobert Drehmelreturns 806c84d0b1SRobert Drehmel.Dv NULL . 816c84d0b1SRobert DrehmelBoth functions return 826c84d0b1SRobert Drehmel.Dv NULL 836c84d0b1SRobert Drehmelif an error occurs. 846c84d0b1SRobert Drehmel.Sh SEE ALSO 856c84d0b1SRobert Drehmel.Xr bsearch 3 , 866c84d0b1SRobert Drehmel.Xr hsearch 3 , 876c84d0b1SRobert Drehmel.Xr tsearch 3 8824a0682cSRuslan Ermilov.Sh STANDARDS 8924a0682cSRuslan ErmilovThe 9024a0682cSRuslan Ermilov.Fn lsearch 9124a0682cSRuslan Ermilovand 9224a0682cSRuslan Ermilov.Fn lfind 9324a0682cSRuslan Ermilovfunctions conform to 9424a0682cSRuslan Ermilov.St -p1003.1-2001 . 956c84d0b1SRobert Drehmel.Sh HISTORY 966c84d0b1SRobert DrehmelThe 976c84d0b1SRobert Drehmel.Fn lsearch 986c84d0b1SRobert Drehmeland 996c84d0b1SRobert Drehmel.Fn lfind 1006c84d0b1SRobert Drehmelfunctions appeared in 1016c84d0b1SRobert Drehmel.Bx 4.2 . 1026c84d0b1SRobert DrehmelIn 1036c84d0b1SRobert Drehmel.Fx 5.0 , 1046c84d0b1SRobert Drehmelthey reappeared conforming to 1056c84d0b1SRobert Drehmel.St -p1003.1-2001 . 106