OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / man3 / lsearch.3
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\" Copyright 1995 Jim Van Zandt <jrv@vanzandt.mv.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" Corrected prototype and include, aeb, 990927
25 .\"
26 .\" Japanese Version Copyright (c) 1998 Ueyama Rui
27 .\"         all rights reserved.
28 .\" Translated 1998-05-23, Ueyama Rui <rui@linux.or.jp>
29 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
30 .\"
31 .\"WORD:        linear search   線形検索
32 .\"
33 .TH LSEARCH 3  1999-09-27 "GNU" "Linux Programmer's Manual"
34 .SH 名前
35 lfind, lsearch \- 配列を線形検索する
36 .SH 書式
37 .nf
38 .B #include <search.h>
39 .sp
40 .BI "void *lfind(const void *" key ", const void *" base ", size_t *" nmemb ,
41 .BI "         size_t " size ", int(*" compar ")(const void *, const void *));"
42 .sp
43 .BI "void *lsearch(const void *" key ", void *" base ", size_t *" nmemb ,
44 .BI "         size_t " size ", int(*" compar ")(const void *, const void *));"
45 .fi
46 .SH 説明
47 .BR lfind ()
48
49 .BR lsearch ()
50 は、
51 .I size
52 バイトの要素
53 .I *nmemb
54 個からなる配列
55 .I base
56 から、
57 .I key
58 を線形検索する。比較を行うのは
59 .I compar
60 が参照している関数で、
61 これは 2つの引き数を持ち、1つめの引き数が
62 .I key
63 を、2つめの引き数は配列メンバーを指す。また
64 .I compar
65 は、
66 .I key
67 が配列のメンバーとマッチしたなら 0、そうでなければ
68 0 以外を返すことが期待されている。
69 .PP
70 .BR lsearch ()
71 は、マッチする要素を見つけられなかったとき、
72 配列の最後に
73 .I key
74 をつけ加える。そして
75 .I *nmemb
76 を 1 ふやす。
77 したがって、この関数を使用する際には、マッチする要素が存在するか、
78 もしくは配列に要素を追加するための領域があるか、を把握しておく必要がある。
79 .SH 返り値
80 .BR lfind ()
81 の返り値は、配列のマッチしたメンバーへのポインタである。
82 もしマッチするメンバーが見つからないと NULL を返す。
83 .BR lsearch ()
84 の返り値も、配列のマッチしたメンバーへのポインタである。
85 マッチするメンバーが見つからなかったときは、
86 新たにつけ加えたメンバーへのポインタを返す。
87 .SH 準拠
88 SVr4, 4.3BSD, POSIX.1-2001.
89 libc には libc-4.6.27 以降で実装されている。
90 .SH バグ
91 関数の名前の選び方がよくない。
92 .SH 関連項目
93 .BR bsearch (3),
94 .BR hsearch (3),
95 .BR tsearch (3)