OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man3 / scandir.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\" Modified Sat Jul 24 18:26:16 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Thu Apr 11 17:11:33 1996 by Andries Brouwer (aeb@cwi.nl):
29 .\"     Corrected type of compar routines, as suggested by
30 .\"     Miguel Barreiro (enano@avalon.yaix.es).  Added example.
31 .\" Modified Sun Sep 24 20:15:46 2000 by aeb, following Petter Reinholdtsen.
32 .\" Modified 2001-12-26 by aeb, following Joey. Added versionsort.
33 .\"
34 .\" FIXME glibc 2.15 adds scandirat()
35 .\"
36 .\" Japanese Version Copyright (c) 1998 Hiroaki Nagoya all rights reserved.
37 .\" Translated Thu May 28 1998 by Hiroaki Nagoya <nagoya@is.titech.ac.jp>
38 .\" Updated & Modified Sat Jan 19 18:22:21 JST 2002
39 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
40 .\" Updated & Modified Sun Jan 16 08:12:04 JST 2005
41 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
42 .\"
43 .TH SCANDIR 3  2011-09-08 "GNU" "Linux Programmer's Manual"
44 .\"O .SH NAME
45 .SH 名前
46 .\"O scandir, alphasort, versionsort \- scan a directory for matching entries
47 scandir, alphasort, versionsort \- ディレクトリを走査する
48 .\"O .SH SYNOPSIS
49 .SH 書式
50 .nf
51 .B #include <dirent.h>
52 .sp
53 .BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
54 .RS
55 .BI "int (*" filter ")(const struct dirent *),"
56 .BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
57 .RE
58 .sp
59 .BI "int alphasort(const void *" a ", const void *" b );
60 .sp
61 .BI "int versionsort(const void *" a ", const void *" b );
62 .fi
63 .sp
64 .in -4n
65 .\"O Feature Test Macro Requirements for glibc (see
66 .\"O .BR feature_test_macros (7)):
67 glibc 向けの機能検査マクロの要件
68 .RB ( feature_test_macros (7)
69 参照):
70 .in
71 .sp
72 .BR scandir (),
73 .BR alphasort ():
74 _BSD_SOURCE || _SVID_SOURCE
75 .br
76 .BR versionsort ():
77 _GNU_SOURCE
78 .\"O .SH DESCRIPTION
79 .SH 説明
80 .\"O The
81 .\"O .BR scandir ()
82 .\"O function scans the directory \fIdirp\fP, calling
83 .\"O \fIfilter\fP() on each directory entry.
84 .\"O Entries for which
85 .\"O \fIfilter\fP() returns nonzero are stored in strings allocated via
86 .\"O .BR malloc (3),
87 .\"O sorted using
88 .\"O .BR qsort (3)
89 .\"O with the comparison
90 .\"O function \fIcompar\fP() and collected in array \fInamelist\fP
91 .\"O which is allocated via
92 .\"O .BR malloc (3).
93 .\"O If \fIfilter\fP is NULL, all entries are selected.
94 関数
95 .BR scandir ()
96 はディレクトリ \fIdirp\fP を走査し、
97 ディレクトリの各エントリを引き数として
98 .BR filter ()
99 を呼び出す。
100 .BR filter ()
101 が 0 以外の値を返すエントリは
102 .BR malloc (3)
103 によって
104 確保された文字列に保存され、比較関数
105 .BR compar ()
106 を用いて
107 .BR qsort (3)
108 によりソートされ、
109 .BR malloc (3)
110 により確保された配列
111 \fInamelist\fP にまとめられる。
112 \fIfilter\fP が NULL ならば、すべてのエントリが選択される。
113 .LP
114 .\"O The
115 .\"O .BR alphasort ()
116 .\"O and
117 .\"O .BR versionsort ()
118 .\"O functions can be used as the comparison function
119 .\"O .IR compar ().
120 比較関数
121 .IR compar ()
122 には
123 .BR alphasort ()
124 関数と
125 .BR versionsort ()
126 関数を使うことができる。
127 .\"O The former sorts directory entries using
128 .\"O .BR strcoll (3),
129 .\"O the latter using
130 .\"O .BR strverscmp (3)
131 .\"O on the strings \fI(*a)\->d_name\fP and \fI(*b)\->d_name\fP.
132 .BR alphasort ()
133
134 .BR strcoll (3)
135 を用いてディレクトリエントリをソートし、
136 .BR versionsort ()
137 は文字列 \fI(*a)\->d_name\fP と \fI(*b)\->d_name\fP に対して
138 .BR strverscmp (3)
139 を用いる。
140 .\"O .SH "RETURN VALUE"
141 .SH 返り値
142 .\"O The
143 .\"O .BR scandir ()
144 .\"O function returns the number of directory entries
145 .\"O selected or \-1 if an error occurs.
146 関数
147 .BR scandir ()
148 は選択されたエントリの数か、
149 (エラーが発生した場合) \-1 を返す。
150 .PP
151 .\"O The
152 .\"O .BR alphasort ()
153 .\"O and
154 .\"O .BR versionsort ()
155 .\"O functions return an integer less than, equal to,
156 .\"O or greater than zero if the first argument is considered to be
157 .\"O respectively less than, equal to, or greater than the second.
158 関数
159 .BR alphasort ()
160
161 .BR versionsort ()
162 は 1 番目の引き数が 2 番目の引き数に対して、
163 [小さい/等しい/大きい] かに応じて、0 より [小さい/等しい/大きい] 値を返す。
164 .\"O .SH ERRORS
165 .SH エラー
166 .TP
167 .B ENOENT
168 .\"O The path in \fIdirp\fR does not exist.
169 \fIdirp\fR で指定されたパスが存在しない。
170 .TP
171 .B ENOMEM
172 .\"O Insufficient memory to complete the operation.
173 動作を完遂するにはメモリが足りない。
174 .TP
175 .B ENOTDIR
176 .\"O The path in \fIdirp\fR is not a directory.
177 \fIdirp\fR で指定されたパスがディレクトリではない。
178 .\"O .SH VERSIONS
179 .SH バージョン
180 .\"O .BR versionsort ()
181 .\"O was added to glibc in version 2.1.
182 .BR versionsort ()
183 は、glibc バージョン 2.1 で追加された。
184 .\"O .SH "CONFORMING TO"
185 .SH 準拠
186 .\"O .BR alphasort ()
187 .\"O and
188 .\"O .BR scandir ()
189 .\"O are specified in POSIX.1-2008, and are widely available.
190 .\"O .BR versionsort ()
191 .\"O is a GNU extension.
192 .BR alphasort ()
193
194 .BR scandir ()
195 は POSIX.1-2008 で規定されており、広く利用可能である。
196 .BR versionsort ()
197 は GNU 拡張である。
198 .LP
199 .\"O The functions
200 .\"O .BR scandir ()
201 .\"O and
202 .\"O .BR alphasort ()
203 .\"O are from 4.3BSD, and have been available under Linux since libc4.
204 関数
205 .BR scandir ()
206
207 .BR alphasort ()
208 は 4.3BSD から取り入れられ、Linux では libc4 から使用可能になった。
209 .\"O Libc4 and libc5 use the more precise prototype
210 libc4 と libc5 では以下のようなもっと詳細なプロトタイプを使っている。
211 .sp
212 .nf
213     int alphasort(const struct dirent ** a,
214                   const struct dirent **b);
215 .fi
216 .sp
217 .\"O but glibc 2.0 returns to the imprecise BSD prototype.
218 しかし glibc 2.0 では不正確な BSD のプロトタイプに戻った。
219 .LP
220 .\"O The function
221 .\"O .BR versionsort ()
222 .\"O is a GNU extension, available since glibc 2.1.
223 関数
224 .BR versionsort ()
225 は GNU の拡張であり、glibc 2.1 以降で使用可能である。
226 .LP
227 .\"O Since glibc 2.1,
228 .\"O .BR alphasort ()
229 .\"O calls
230 .\"O .BR strcoll (3);
231 .\"O earlier it used
232 .\"O .BR strcmp (3).
233 glibc 2.1 以降では
234 .BR alphasort ()
235
236 .BR strcoll (3)
237 を呼び出す。
238 .BR alphasort ()
239 は以前は
240 .BR strcmp (3)
241 を使っていた。
242 .\"O .SH EXAMPLE
243 .SH 例
244 .nf
245 #define _SVID_SOURCE
246 .\"O /* print files in current directory in reverse order */
247 /* カレントディレクトリのファイルを逆順に出力する */
248 #include <dirent.h>
249
250 int
251 main(void)
252 {
253     struct dirent **namelist;
254     int n;
255
256     n = scandir(".", &namelist, 0, alphasort);
257     if (n < 0)
258         perror("scandir");
259     else {
260         while (n\-\-) {
261             printf("%s\en", namelist[n]\->d_name);
262             free(namelist[n]);
263         }
264         free(namelist);
265     }
266 }
267 .fi
268 .\"O .SH "SEE ALSO"
269 .SH 関連項目
270 .BR closedir (3),
271 .BR fnmatch (3),
272 .BR opendir (3),
273 .BR readdir (3),
274 .BR rewinddir (3),
275 .BR seekdir (3),
276 .BR strcmp (3),
277 .BR strcoll (3),
278 .BR strverscmp (3),
279 .BR telldir (3)