flag fields are u_int's
[unix-history] / usr / src / lib / libc / stdlib / bsearch.3
CommitLineData
d17d385d 1.\" Copyright (c) 1990 The Regents of the University of California.
a74efd49
KB
2.\" All rights reserved.
3.\"
d17d385d 4.\" %sccs.include.redist.man%
a74efd49 5.\"
d17d385d 6.\" @(#)bsearch.3 5.2 (Berkeley) %G%
a74efd49
KB
7.\"
8.TH BSEARCH 3 ""
9.UC 7
10.SH NAME
11bsearch - binary search of a sorted table
12.SH SYNOPSIS
13.nf
14.ft B
15#include <stdlib.h>
16.sp
17char *
18bsearch(const void *key, const void *base,
19size_t nmemb, size_t size,
20int (*compar) (const void *, const void *));
21.ft R
22.fi
23.SH DESCRIPTION
24The
25.I bsearch
26function searches an array of
27.I nmemb
28objects, the inital member of which is
29pointed to by
30.IR base ,
31for a member that matches the object pointed to by
32.IR key .
33The size of each member of the array is specified by
34.I size .
35.PP
36The contents of the array should be in ascending sorted order according
37to the comparison function referenced by
38.IR compar .
39.I Compar
40is called with two arguments that point to the
41.I key
42object and to an array member, in that order, and must return an integer
43less than, equal to, or greater than zero if the
44.I key
45object is considered, respectively, to be less than, equal to, or to
46greater than the array member.
47.PP
48The
49.I bsearch
50function returns a pointer to a matching member of the array, or a null
51pointer if no match is found.
52If two members compare as equal, which member is matched is unspecified.
53.SH "SEE ALSO"
54hsearch(3), lsearch(3), qsort(3), tsearch(3)
55.SH STANDARDS
d17d385d
KB
56.B Bsearch
57conforms to ANSI X3.159-1989 (``ANSI C'').