date and time created 89/10/14 14:29:04 by bostic
[unix-history] / usr / src / lib / libc / stdlib / bsearch.3
CommitLineData
a74efd49
KB
1.\" Copyright (c) 1989 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)bsearch.3 5.1 (Berkeley) %G%
17.\"
18.TH BSEARCH 3 ""
19.UC 7
20.SH NAME
21bsearch - binary search of a sorted table
22.SH SYNOPSIS
23.nf
24.ft B
25#include <stdlib.h>
26.sp
27char *
28bsearch(const void *key, const void *base,
29size_t nmemb, size_t size,
30int (*compar) (const void *, const void *));
31.ft R
32.fi
33.SH DESCRIPTION
34The
35.I bsearch
36function searches an array of
37.I nmemb
38objects, the inital member of which is
39pointed to by
40.IR base ,
41for a member that matches the object pointed to by
42.IR key .
43The size of each member of the array is specified by
44.I size .
45.PP
46The contents of the array should be in ascending sorted order according
47to the comparison function referenced by
48.IR compar .
49.I Compar
50is called with two arguments that point to the
51.I key
52object and to an array member, in that order, and must return an integer
53less than, equal to, or greater than zero if the
54.I key
55object is considered, respectively, to be less than, equal to, or to
56greater than the array member.
57.PP
58The
59.I bsearch
60function returns a pointer to a matching member of the array, or a null
61pointer if no match is found.
62If two members compare as equal, which member is matched is unspecified.
63.SH "SEE ALSO"
64hsearch(3), lsearch(3), qsort(3), tsearch(3)
65.SH STANDARDS
66The
67.I bsearch
68function is ANSI C compatible.