OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / release / man3 / scandir.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 18:26:16 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified Thu Apr 11 17:11:33 1996 by Andries Brouwer (aeb@cwi.nl):
31 .\"     Corrected type of compar routines, as suggested by
32 .\"     Miguel Barreiro (enano@avalon.yaix.es).  Added example.
33 .\" Modified Sun Sep 24 20:15:46 2000 by aeb, following Petter Reinholdtsen.
34 .\" Modified 2001-12-26 by aeb, following Joey. Added versionsort.
35 .\"
36 .\" The pieces on scandirat(3) were copyright and licensed as follows.
37 .\"
38 .\" Copyright (c) 2012, Mark R. Bannister <cambridge@users.sourceforge.net>
39 .\"        based on text in mkfifoat.3 Copyright (c) 2006, Michael Kerrisk
40 .\"
41 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
42 .\" This is free documentation; you can redistribute it and/or
43 .\" modify it under the terms of the GNU General Public License as
44 .\" published by the Free Software Foundation; either version 2 of
45 .\" the License, or (at your option) any later version.
46 .\"
47 .\" The GNU General Public License's references to "object code"
48 .\" and "executables" are to be interpreted as the output of any
49 .\" document formatting or typesetting system, including
50 .\" intermediate and printed output.
51 .\"
52 .\" This manual is distributed in the hope that it will be useful,
53 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
54 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55 .\" GNU General Public License for more details.
56 .\"
57 .\" You should have received a copy of the GNU General Public
58 .\" License along with this manual; if not, see
59 .\" <http://www.gnu.org/licenses/>.
60 .\" %%%LICENSE_END
61 .\"
62 .\"*******************************************************************
63 .\"
64 .\" This file was generated with po4a. Translate the source file.
65 .\"
66 .\"*******************************************************************
67 .\"
68 .\" Japanese Version Copyright (c) 1998 Hiroaki Nagoya all rights reserved.
69 .\" Translated Thu May 28 1998 by Hiroaki Nagoya <nagoya@is.titech.ac.jp>
70 .\" Updated & Modified Sat Jan 19 18:22:21 JST 2002
71 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
72 .\" Updated & Modified Sun Jan 16 08:12:04 JST 2005
73 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
74 .\"
75 .TH SCANDIR 3 2014\-05\-28 GNU "Linux Programmer's Manual"
76 .SH 名前
77 scandir, scandirat, alphasort, versionsort \- ディレクトリを走査する
78 .SH 書式
79 .nf
80 \fB#include <dirent.h>\fP
81 .sp
82 \fBint scandir(const char *\fP\fIdirp\fP\fB, struct dirent ***\fP\fInamelist\fP\fB,\fP
83 .RS
84 \fBint (*\fP\fIfilter\fP\fB)(const struct dirent *),\fP
85 \fBint (*\fP\fIcompar\fP\fB)(const struct dirent **, const struct dirent **));\fP
86 .RE
87 .sp
88 \fBint alphasort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP
89 .sp
90 \fBint versionsort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP
91
92 \fB#include <fcntl.h>\fP          /* AT_* 定数の定義 */
93 \fB#include <dirent.h>\fP
94 .sp
95 .fi
96 \fBint scandirat(int \fP\fIdirfd\fP\fB, const char *\fP\fIdirp\fP\fB,\fP \fBstruct dirent
97 ***\fP\fInamelist\fP\fB,\fP
98 .nf
99 .RS
100 \fBint (*\fP\fIfilter\fP\fB)(const struct dirent *),\fP
101 \fBint (*\fP\fIcompar\fP\fB)(const struct dirent **, const struct dirent **));\fP
102 .RE
103 .fi
104 .sp
105 .in -4n
106 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
107 .in
108 .sp
109 \fBscandir\fP(), \fBalphasort\fP():
110 .br
111 .RS 4
112 .PD 0
113 .ad b
114 _BSD_SOURCE || _SVID_SOURCE
115 .br
116 || /* glibc 2.10 以降: */
117 .RS 4
118 (_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
119 .RE
120 .PD
121 .RE
122 .sp
123 \fBversionsort\fP(): _GNU_SOURCE
124 .sp
125 \fBscandirat\fP(): _GNU_SOURCE
126 .SH 説明
127 関数 \fBscandir\fP()  はディレクトリ \fIdirp\fP を走査し、 ディレクトリの各エントリーを引き数として \fBfilter\fP()
128 を呼び出す。 \fBfilter\fP()  が 0 以外の値を返すエントリーは \fBmalloc\fP(3)  によって 確保された文字列に保存され、比較関数
129 \fBcompar\fP()  を用いて \fBqsort\fP(3)  によりソートされ、 \fBmalloc\fP(3)  により確保された配列
130 \fInamelist\fP にまとめられる。 \fIfilter\fP が NULL ならば、すべてのエントリーが選択される。
131 .LP
132 比較関数 \fIcompar\fP()  には \fBalphasort\fP()  関数と \fBversionsort\fP()  関数を使うことができる。
133 \fBalphasort\fP()  は \fBstrcoll\fP(3)  を用いてディレクトリエントリーをソートし、 \fBversionsort\fP()
134 は文字列 \fI(*a)\->d_name\fP と \fI(*b)\->d_name\fP に対して \fBstrverscmp\fP(3)  を用いる。
135 .SS scandirat()
136 \fBscandirat\fP() 関数は \fBscandir\fP() と全く同様の動作をする。差分についてはここで説明する。
137
138 \fIdirp\fP で指定されたパス名が相対パスの場合、ファイルディスクリプター \fIdirfd\fP が参照するディレクトリからの相対パスと解釈される
139 (これに対して、\fBscandir\fP() の場合は、相対パス名は、呼び出したプロセスのカレントワーキングディレクトリからの相対パスと解釈される)。
140
141 \fIdirp\fP が相対パスで \fIdirfd\fP が特別な値 \fBAT_FDCWD\fP の場合、 \fIdirp\fP は (\fBscandir\fP() と同様に)
142 呼び出したプロセスのカレントワーキングディレクトリからの相対パスと解釈される。
143
144 \fIdirp\fP が絶対パスの場合、\fIdirfd\fP は無視される。
145 .PP
146 \fBscandirat\fP() が必要な理由については \fBopenat\fP(2) を参照すること。
147 .SH 返り値
148 \fBscandir\fP() 関数は、選択されたディレクトリのエントリー数を返す。 エラーの場合、 \-1 を返し、 \fIerrno\fP
149 にエラーの原因を示す値を設定する。
150 .PP
151 関数 \fBalphasort\fP()  と \fBversionsort\fP()  は 1 番目の引き数が 2 番目の引き数に対して、
152 [小さい/等しい/大きい] かに応じて、0 より [小さい/等しい/大きい] 値を返す。
153 .SH エラー
154 .TP 
155 \fBENOENT\fP
156 \fIdirp\fP で指定されたパスが存在しない。
157 .TP 
158 \fBENOMEM\fP
159 操作を完了するのに十分なメモリーがない。
160 .TP 
161 \fBENOTDIR\fP
162 \fIdirp\fP で指定されたパスがディレクトリではない。
163 .PP
164 \fBscandirat\fP() では追加で以下のエラーも発生する:
165 .TP 
166 \fBEBADF\fP
167 \fIdirfd\fP が有効なファイルディスクリプターではない。
168 .TP 
169 \fBENOTDIR\fP
170 \fIdirp\fP が相対パスで、\fIdirfd\fP がディレクトリ以外のファイルを参照している
171 ファイルディスクリプターである。
172 .SH バージョン
173 \fBversionsort\fP()  は、glibc バージョン 2.1 で追加された。
174
175 \fBscandirat\fP()  は glibc バージョン 2.15 で追加された。
176 .SH 準拠
177 \fBalphasort\fP(), \fBscandir\fP(): 4.3BSD, POSIX.1\-2008.
178
179 .\" .LP
180 .\" The functions
181 .\" .BR scandir ()
182 .\" and
183 .\" .BR alphasort ()
184 .\" are from 4.3BSD, and have been available under Linux since libc4.
185 .\" Libc4 and libc5 use the more precise prototype
186 .\" .sp
187 .\" .nf
188 .\"    int alphasort(const struct dirent ** a,
189 .\"                  const struct dirent **b);
190 .\" .fi
191 .\" .sp
192 .\" but glibc 2.0 returns to the imprecise BSD prototype.
193 \fBversionsort\fP() と \fBscandirat\fP() は GNU 拡張である。
194 .SH 注意
195 glibc 2.1 以降では \fBalphasort\fP()  は \fBstrcoll\fP(3)  を呼び出す。 \fBalphasort\fP()  は以前は
196 \fBstrcmp\fP(3)  を使っていた。
197 .SH 例
198 .nf
199 #define _SVID_SOURCE
200 /* カレントディレクトリのファイルを逆順に出力する */
201 #include <dirent.h>
202
203 int
204 main(void)
205 {
206     struct dirent **namelist;
207     int n;
208
209     n = scandir(".", &namelist, NULL, alphasort);
210     if (n < 0)
211         perror("scandir");
212     else {
213         while (n\-\-) {
214             printf("%s\en", namelist[n]\->d_name);
215             free(namelist[n]);
216         }
217         free(namelist);
218     }
219 }
220 .fi
221 .SH 関連項目
222 \fBclosedir\fP(3), \fBfnmatch\fP(3), \fBopendir\fP(3), \fBreaddir\fP(3),
223 \fBrewinddir\fP(3), \fBseekdir\fP(3), \fBstrcmp\fP(3), \fBstrcoll\fP(3),
224 \fBstrverscmp\fP(3), \fBtelldir\fP(3)
225 .SH この文書について
226 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
227 である。プロジェクトの説明とバグ報告に関する情報は
228 http://www.kernel.org/doc/man\-pages/ に書かれている。