1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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.
34 .\" FIXME glibc 2.15 adds scandirat()
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>
43 .TH SCANDIR 3 2011-09-08 "GNU" "Linux Programmer's Manual"
46 .\"O scandir, alphasort, versionsort \- scan a directory for matching entries
47 scandir, alphasort, versionsort \- ディレクトリを走査する
51 .B #include <dirent.h>
53 .BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
55 .BI "int (*" filter ")(const struct dirent *),"
56 .BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
59 .BI "int alphasort(const void *" a ", const void *" b );
61 .BI "int versionsort(const void *" a ", const void *" b );
65 .\"O Feature Test Macro Requirements for glibc (see
66 .\"O .BR feature_test_macros (7)):
68 .RB ( feature_test_macros (7)
74 _BSD_SOURCE || _SVID_SOURCE
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
89 .\"O with the comparison
90 .\"O function \fIcompar\fP() and collected in array \fInamelist\fP
91 .\"O which is allocated via
93 .\"O If \fIfilter\fP is NULL, all entries are selected.
96 はディレクトリ \fIdirp\fP を走査し、
111 \fInamelist\fP にまとめられる。
112 \fIfilter\fP が NULL ならば、すべてのエントリが選択される。
115 .\"O .BR alphasort ()
117 .\"O .BR versionsort ()
118 .\"O functions can be used as the comparison function
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.
137 は文字列 \fI(*a)\->d_name\fP と \fI(*b)\->d_name\fP に対して
140 .\"O .SH "RETURN VALUE"
144 .\"O function returns the number of directory entries
145 .\"O selected or \-1 if an error occurs.
149 (エラーが発生した場合) \-1 を返す。
152 .\"O .BR alphasort ()
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.
162 は 1 番目の引き数が 2 番目の引き数に対して、
163 [小さい/等しい/大きい] かに応じて、0 より [小さい/等しい/大きい] 値を返す。
168 .\"O The path in \fIdirp\fR does not exist.
169 \fIdirp\fR で指定されたパスが存在しない。
172 .\"O Insufficient memory to complete the operation.
176 .\"O The path in \fIdirp\fR is not a directory.
177 \fIdirp\fR で指定されたパスがディレクトリではない。
180 .\"O .BR versionsort ()
181 .\"O was added to glibc in version 2.1.
183 は、glibc バージョン 2.1 で追加された。
184 .\"O .SH "CONFORMING TO"
186 .\"O .BR alphasort ()
189 .\"O are specified in POSIX.1-2008, and are widely available.
190 .\"O .BR versionsort ()
191 .\"O is a GNU extension.
195 は POSIX.1-2008 で規定されており、広く利用可能である。
202 .\"O .BR alphasort ()
203 .\"O are from 4.3BSD, and have been available under Linux since libc4.
208 は 4.3BSD から取り入れられ、Linux では libc4 から使用可能になった。
209 .\"O Libc4 and libc5 use the more precise prototype
210 libc4 と libc5 では以下のようなもっと詳細なプロトタイプを使っている。
213 int alphasort(const struct dirent ** a,
214 const struct dirent **b);
217 .\"O but glibc 2.0 returns to the imprecise BSD prototype.
218 しかし glibc 2.0 では不正確な BSD のプロトタイプに戻った。
221 .\"O .BR versionsort ()
222 .\"O is a GNU extension, available since glibc 2.1.
225 は GNU の拡張であり、glibc 2.1 以降で使用可能である。
227 .\"O Since glibc 2.1,
228 .\"O .BR alphasort ()
230 .\"O .BR strcoll (3);
246 .\"O /* print files in current directory in reverse order */
247 /* カレントディレクトリのファイルを逆順に出力する */
253 struct dirent **namelist;
256 n = scandir(".", &namelist, 0, alphasort);
261 printf("%s\en", namelist[n]\->d_name);