.\" Copyright 1995 Jim Van Zandt .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Corrected prototype and include, aeb, 990927 .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1998 Ueyama Rui .\" all rights reserved. .\" Translated 1998-05-23, Ueyama Rui .\" Updated 2005-02-26, Akihiro MOTOKI .\" .TH LSEARCH 3 1999\-09\-27 GNU "Linux Programmer's Manual" .SH 名前 lfind, lsearch \- 配列を線形検索する .SH 書式 .nf \fB#include \fP .sp \fBvoid *lfind(const void *\fP\fIkey\fP\fB, const void *\fP\fIbase\fP\fB, size_t *\fP\fInmemb\fP\fB,\fP \fB size_t \fP\fIsize\fP\fB, int(*\fP\fIcompar\fP\fB)(const void *, const void *));\fP .sp \fBvoid *lsearch(const void *\fP\fIkey\fP\fB, void *\fP\fIbase\fP\fB, size_t *\fP\fInmemb\fP\fB,\fP \fB size_t \fP\fIsize\fP\fB, int(*\fP\fIcompar\fP\fB)(const void *, const void *));\fP .fi .SH 説明 \fBlfind\fP() と \fBlsearch\fP() は、 \fIsize\fP バイトの要素 \fI*nmemb\fP 個からなる配列 \fIbase\fP から、 \fIkey\fP を線形検索する。比較を行うのは \fIcompar\fP が参照している関数で、 これは 2つの引き数を持ち、1つめの引き数が \fIkey\fP を、2つめの引き数は配列メンバーを指す。また \fIcompar\fP は、 \fIkey\fP が配列のメンバーとマッチしたなら 0、そうでなければ 0 以外を返すことが期待されている。 .PP \fBlsearch\fP() は、マッチする要素を見つけられなかったとき、 配列の最後に \fIkey\fP をつけ加える。そして \fI*nmemb\fP を 1 ふやす。 したがって、この関数を使用する際には、マッチする要素が存在するか、 もしくは配列に要素を追加するための領域があるか、を把握しておく必要がある。 .SH 返り値 \fBlfind\fP() の返り値は、配列のマッチしたメンバーへのポインタである。 もしマッチするメンバーが見つからないと NULL を返す。 \fBlsearch\fP() の返り値も、配列のマッチしたメンバーへのポインタである。 マッチするメンバーが見つからなかったときは、 新たにつけ加えたメンバーへのポインタを返す。 .SH 準拠 SVr4, 4.3BSD, POSIX.1\-2001. libc には libc\-4.6.27 以降で実装されている。 .SH バグ 関数の名前の選び方がよくない。 .SH 関連項目 \fBbsearch\fP(3), \fBhsearch\fP(3), \fBtsearch\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。