OSDN Git Service

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