-mdoc (version 3)
[unix-history] / usr / src / lib / libc / stdlib / bsearch.3
CommitLineData
ae59e04c 1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
a74efd49
KB
2.\" All rights reserved.
3.\"
d17d385d 4.\" %sccs.include.redist.man%
a74efd49 5.\"
ae59e04c 6.\" @(#)bsearch.3 5.4 (Berkeley) %G%
a74efd49 7.\"
ae59e04c
CL
8.Dd
9.Dt BSEARCH 3
10.Os
11.Sh NAME
12.Nm bsearch
13.Nd binary search of a sorted table
14.Sh SYNOPSIS
15.Fd #include <stdlib.h>
16.Ft void *
17.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)"
18.Sh DESCRIPTION
a74efd49 19The
ae59e04c 20.Fn bsearch
a74efd49 21function searches an array of
ae59e04c 22.Fa nmemb
a74efd49
KB
23objects, the inital member of which is
24pointed to by
ae59e04c 25.Fa base ,
a74efd49 26for a member that matches the object pointed to by
ae59e04c 27.Fa key .
a74efd49 28The size of each member of the array is specified by
ae59e04c
CL
29.Fa size .
30.Pp
a74efd49
KB
31The contents of the array should be in ascending sorted order according
32to the comparison function referenced by
ae59e04c
CL
33.Fa compar .
34The
35.Fa compar
36routine
37is expected to have two
38two arguments which point to the
39.Fa key
40object and to an array member, in that order, and should return an integer
a74efd49 41less than, equal to, or greater than zero if the
ae59e04c
CL
42.Fa key
43object is found, respectively, to be less than, to match, or be
a74efd49 44greater than the array member.
ae59e04c 45.Sh RETURN VALUES
a74efd49 46The
ae59e04c 47.Fn bsearch
a74efd49
KB
48function returns a pointer to a matching member of the array, or a null
49pointer if no match is found.
50If two members compare as equal, which member is matched is unspecified.
ae59e04c
CL
51.Sh SEE ALSO
52.Xr hsearch 3 ,
53.Xr lsearch 3 ,
54.Xr qsort 3 ,
55.\" .Xr tsearch 3
56.Sh STANDARDS
57The
58.Fn bsearch
59function conforms to
60.St -ansiC .