OSDN Git Service

a7cc0470a90038f21ff30519b118ab37606a5eb7
[linuxjm/LDP_man-pages.git] / draft / 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 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .TH SCANDIR 3 2013\-04\-19 GNU "Linux Programmer's Manual"
42 .SH 名前
43 scandir, alphasort, versionsort \- ディレクトリを走査する
44 .SH 書式
45 .nf
46 \fB#include <dirent.h>\fP
47 .sp
48 \fBint scandir(const char *\fP\fIdirp\fP\fB, struct dirent ***\fP\fInamelist\fP\fB,\fP
49 .RS
50 \fBint (*\fP\fIfilter\fP\fB)(const struct dirent *),\fP
51 \fBint (*\fP\fIcompar\fP\fB)(const struct dirent **, const struct dirent **));\fP
52 .RE
53 .sp
54 \fBint alphasort(const void *\fP\fIa\fP\fB, const void *\fP\fIb\fP\fB);\fP
55 .sp
56 \fBint versionsort(const void *\fP\fIa\fP\fB, const void *\fP\fIb\fP\fB);\fP
57 .fi
58 .sp
59 .in -4n
60 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
61 .in
62 .sp
63 \fBscandir\fP(), \fBalphasort\fP(): _BSD_SOURCE || _SVID_SOURCE
64 .br
65 \fBversionsort\fP(): _GNU_SOURCE
66 .SH 説明
67 関数 \fBscandir\fP()  はディレクトリ \fIdirp\fP を走査し、 ディレクトリの各エントリを引き数として \fBfilter\fP()
68 を呼び出す。 \fBfilter\fP()  が 0 以外の値を返すエントリは \fBmalloc\fP(3)  によって 確保された文字列に保存され、比較関数
69 \fBcompar\fP()  を用いて \fBqsort\fP(3)  によりソートされ、 \fBmalloc\fP(3)  により確保された配列
70 \fInamelist\fP にまとめられる。 \fIfilter\fP が NULL ならば、すべてのエントリが選択される。
71 .LP
72 比較関数 \fIcompar\fP()  には \fBalphasort\fP()  関数と \fBversionsort\fP()  関数を使うことができる。
73 \fBalphasort\fP()  は \fBstrcoll\fP(3)  を用いてディレクトリエントリをソートし、 \fBversionsort\fP()  は文字列
74 \fI(*a)\->d_name\fP と \fI(*b)\->d_name\fP に対して \fBstrverscmp\fP(3)  を用いる。
75 .SH 返り値
76 \fBscandir\fP() 関数は、選択されたディレクトリのエントリ数を返す。 エラーの場合、 \-1 を返し、 \fIerrno\fP
77 にエラーの原因を示す値を設定する。
78 .PP
79 関数 \fBalphasort\fP()  と \fBversionsort\fP()  は 1 番目の引き数が 2 番目の引き数に対して、
80 [小さい/等しい/大きい] かに応じて、0 より [小さい/等しい/大きい] 値を返す。
81 .SH エラー
82 .TP 
83 \fBENOENT\fP
84 \fIdirp\fP で指定されたパスが存在しない。
85 .TP 
86 \fBENOMEM\fP
87 操作を完了するのに十分なメモリがない。
88 .TP 
89 \fBENOTDIR\fP
90 \fIdirp\fP で指定されたパスがディレクトリではない。
91 .SH バージョン
92 \fBversionsort\fP()  は、glibc バージョン 2.1 で追加された。
93 .SH 準拠
94 \fBalphasort\fP()  と \fBscandir\fP()  は POSIX.1\-2008 で規定されており、広く利用可能である。
95 \fBversionsort\fP()  は GNU 拡張である。
96 .LP
97 関数 \fBscandir\fP()  と \fBalphasort\fP()  は 4.3BSD から取り入れられ、Linux では libc4
98 から使用可能になった。 libc4 と libc5 では以下のようなもっと詳細なプロトタイプを使っている。
99 .sp
100 .nf
101     int alphasort(const struct dirent ** a,
102                   const struct dirent **b);
103 .fi
104 .sp
105 しかし glibc 2.0 では不正確な BSD のプロトタイプに戻った。
106 .LP
107 関数 \fBversionsort\fP()  は GNU の拡張であり、glibc 2.1 以降で使用可能である。
108 .LP
109 glibc 2.1 以降では \fBalphasort\fP()  は \fBstrcoll\fP(3)  を呼び出す。 \fBalphasort\fP()  は以前は
110 \fBstrcmp\fP(3)  を使っていた。
111 .SH 例
112 .nf
113 #define _SVID_SOURCE
114 /* カレントディレクトリのファイルを逆順に出力する */
115 #include <dirent.h>
116
117 int
118 main(void)
119 {
120     struct dirent **namelist;
121     int n;
122
123     n = scandir(".", &namelist, NULL, alphasort);
124     if (n < 0)
125         perror("scandir");
126     else {
127         while (n\-\-) {
128             printf("%s\en", namelist[n]\->d_name);
129             free(namelist[n]);
130         }
131         free(namelist);
132     }
133 }
134 .fi
135 .SH 関連項目
136 \fBclosedir\fP(3), \fBfnmatch\fP(3), \fBopendir\fP(3), \fBreaddir\fP(3),
137 \fBrewinddir\fP(3), \fBscandirat\fP(3), \fBseekdir\fP(3), \fBstrcmp\fP(3),
138 \fBstrcoll\fP(3), \fBstrverscmp\fP(3), \fBtelldir\fP(3)
139 .SH この文書について
140 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
141 である。プロジェクトの説明とバグ報告に関する情報は
142 http://www.kernel.org/doc/man\-pages/ に書かれている。