OSDN Git Service

c0c7c28b4d816fcc823c4c1c9ef67f306df286a0
[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 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .TH SCANDIR 3 2012\-04\-26 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 を返す。
77 .PP
78 関数 \fBalphasort\fP()  と \fBversionsort\fP()  は 1 番目の引き数が 2 番目の引き数に対して、
79 [小さい/等しい/大きい] かに応じて、0 より [小さい/等しい/大きい] 値を返す。
80 .SH エラー
81 .TP 
82 \fBENOENT\fP
83 \fIdirp\fP で指定されたパスが存在しない。
84 .TP 
85 \fBENOMEM\fP
86 操作を完了するのに十分なメモリがない。
87 .TP 
88 \fBENOTDIR\fP
89 \fIdirp\fP で指定されたパスがディレクトリではない。
90 .SH バージョン
91 \fBversionsort\fP()  は、glibc バージョン 2.1 で追加された。
92 .SH 準拠
93 \fBalphasort\fP()  と \fBscandir\fP()  は POSIX.1\-2008 で規定されており、広く利用可能である。
94 \fBversionsort\fP()  は GNU 拡張である。
95 .LP
96 関数 \fBscandir\fP()  と \fBalphasort\fP()  は 4.3BSD から取り入れられ、Linux では libc4
97 から使用可能になった。 libc4 と libc5 では以下のようなもっと詳細なプロトタイプを使っている。
98 .sp
99 .nf
100     int alphasort(const struct dirent ** a,
101                   const struct dirent **b);
102 .fi
103 .sp
104 しかし glibc 2.0 では不正確な BSD のプロトタイプに戻った。
105 .LP
106 関数 \fBversionsort\fP()  は GNU の拡張であり、glibc 2.1 以降で使用可能である。
107 .LP
108 glibc 2.1 以降では \fBalphasort\fP()  は \fBstrcoll\fP(3)  を呼び出す。 \fBalphasort\fP()  は以前は
109 \fBstrcmp\fP(3)  を使っていた。
110 .SH 例
111 .nf
112 #define _SVID_SOURCE
113 /* カレントディレクトリのファイルを逆順に出力する */
114 #include <dirent.h>
115
116 int
117 main(void)
118 {
119     struct dirent **namelist;
120     int n;
121
122     n = scandir(".", &namelist, NULL, alphasort);
123     if (n < 0)
124         perror("scandir");
125     else {
126         while (n\-\-) {
127             printf("%s\en", namelist[n]\->d_name);
128             free(namelist[n]);
129         }
130         free(namelist);
131     }
132 }
133 .fi
134 .SH 関連項目
135 \fBclosedir\fP(3), \fBfnmatch\fP(3), \fBopendir\fP(3), \fBreaddir\fP(3),
136 \fBrewinddir\fP(3), \fBscandirat\fP(3), \fBseekdir\fP(3), \fBstrcmp\fP(3),
137 \fBstrcoll\fP(3), \fBstrverscmp\fP(3), \fBtelldir\fP(3)
138 .SH この文書について
139 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
140 である。プロジェクトの説明とバグ報告に関する情報は
141 http://www.kernel.org/doc/man\-pages/ に書かれている。