Commit | Line | Data |
---|---|---|
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 | |
21 | bsearch - binary search of a sorted table | |
22 | .SH SYNOPSIS | |
23 | .nf | |
24 | .ft B | |
25 | #include <stdlib.h> | |
26 | .sp | |
27 | char * | |
28 | bsearch(const void *key, const void *base, | |
29 | size_t nmemb, size_t size, | |
30 | int (*compar) (const void *, const void *)); | |
31 | .ft R | |
32 | .fi | |
33 | .SH DESCRIPTION | |
34 | The | |
35 | .I bsearch | |
36 | function searches an array of | |
37 | .I nmemb | |
38 | objects, the inital member of which is | |
39 | pointed to by | |
40 | .IR base , | |
41 | for a member that matches the object pointed to by | |
42 | .IR key . | |
43 | The size of each member of the array is specified by | |
44 | .I size . | |
45 | .PP | |
46 | The contents of the array should be in ascending sorted order according | |
47 | to the comparison function referenced by | |
48 | .IR compar . | |
49 | .I Compar | |
50 | is called with two arguments that point to the | |
51 | .I key | |
52 | object and to an array member, in that order, and must return an integer | |
53 | less than, equal to, or greater than zero if the | |
54 | .I key | |
55 | object is considered, respectively, to be less than, equal to, or to | |
56 | greater than the array member. | |
57 | .PP | |
58 | The | |
59 | .I bsearch | |
60 | function returns a pointer to a matching member of the array, or a null | |
61 | pointer if no match is found. | |
62 | If two members compare as equal, which member is matched is unspecified. | |
63 | .SH "SEE ALSO" | |
64 | hsearch(3), lsearch(3), qsort(3), tsearch(3) | |
65 | .SH STANDARDS | |
66 | The | |
67 | .I bsearch | |
68 | function is ANSI C compatible. |