OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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 .\" Japanese Version Copyright (c) 1998 Hiroaki Nagoya all rights reserved.
35 .\" Translated Thu May 28 1998 by Hiroaki Nagoya <nagoya@is.titech.ac.jp>
36 .\" Updated & Modified Sat Jan 19 18:22:21 JST 2002
37 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
38 .\" Updated & Modified Sun Jan 16 08:12:04 JST 2005
39 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
40 .\"
41 .TH SCANDIR 3  2009-02-10 "GNU" "Linux Programmer's Manual"
42 .\"O .SH NAME
43 .SH Ì¾Á°
44 .\"O scandir, alphasort, versionsort \- scan a directory for matching entries
45 scandir, alphasort, versionsort \- ¥Ç¥£¥ì¥¯¥È¥ê¤òÁöºº¤¹¤ë
46 .\"O .SH SYNOPSIS
47 .SH ½ñ¼°
48 .nf
49 .B #include <dirent.h>
50 .sp
51 .BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
52 .RS
53 .BI "int (*" filter ")(const struct dirent *),"
54 .BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
55 .RE
56 .sp
57 .BI "int alphasort(const void *" a ", const void *" b );
58 .sp
59 .BI "int versionsort(const void *" a ", const void *" b );
60 .fi
61 .sp
62 .in -4n
63 .\"O Feature Test Macro Requirements for glibc (see
64 .\"O .BR feature_test_macros (7)):
65 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
66 .RB ( feature_test_macros (7)
67 »²¾È):
68 .in
69 .sp
70 .BR scandir (),
71 .BR alphasort ():
72 _BSD_SOURCE || _SVID_SOURCE
73 .br
74 .BR versionsort ():
75 _GNU_SOURCE
76 .\"O .SH DESCRIPTION
77 .SH ÀâÌÀ
78 .\"O The
79 .\"O .BR scandir ()
80 .\"O function scans the directory \fIdirp\fP, calling
81 .\"O \fIfilter\fP() on each directory entry.
82 .\"O Entries for which
83 .\"O \fIfilter\fP() returns nonzero are stored in strings allocated via
84 .\"O .BR malloc (3),
85 .\"O sorted using
86 .\"O .BR qsort (3)
87 .\"O with the comparison
88 .\"O function \fIcompar\fP() and collected in array \fInamelist\fP
89 .\"O which is allocated via
90 .\"O .BR malloc (3).
91 .\"O If \fIfilter\fP is NULL, all entries are selected.
92 ´Ø¿ô
93 .BR scandir ()
94 ¤Ï¥Ç¥£¥ì¥¯¥È¥ê \fIdirp\fP ¤òÁöºº¤·¡¢
95 ¥Ç¥£¥ì¥¯¥È¥ê¤Î³Æ¥¨¥ó¥È¥ê¤ò°ú¤­¿ô¤È¤·¤Æ
96 .BR filter ()
97 ¤ò¸Æ¤Ó½Ð¤¹¡£
98 .BR filter ()
99 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¥¨¥ó¥È¥ê¤Ï
100 .BR malloc (3)
101 ¤Ë¤è¤Ã¤Æ
102 ³ÎÊݤµ¤ì¤¿Ê¸»úÎó¤ËÊݸ¤µ¤ì¡¢Èæ³Ó´Ø¿ô
103 .BR compar ()
104 ¤òÍѤ¤¤Æ
105 .BR qsort (3)
106 ¤Ë¤è¤ê¥½¡¼¥È¤µ¤ì¡¢
107 .BR malloc (3)
108 ¤Ë¤è¤ê³ÎÊݤµ¤ì¤¿ÇÛÎó
109 \fInamelist\fP ¤Ë¤Þ¤È¤á¤é¤ì¤ë¡£
110 \fIfilter\fP ¤¬ NULL ¤Ê¤é¤Ð¡¢¤¹¤Ù¤Æ¤Î¥¨¥ó¥È¥ê¤¬ÁªÂò¤µ¤ì¤ë¡£
111 .LP
112 .\"O The
113 .\"O .BR alphasort ()
114 .\"O and
115 .\"O .BR versionsort ()
116 .\"O functions can be used as the comparison function
117 .\"O .IR compar ().
118 Èæ³Ó´Ø¿ô
119 .IR compar ()
120 ¤Ë¤Ï
121 .BR alphasort ()
122 ´Ø¿ô¤È
123 .BR versionsort ()
124 ´Ø¿ô¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
125 .\"O The former sorts directory entries using
126 .\"O .BR strcoll (3),
127 .\"O the latter using
128 .\"O .BR strverscmp (3)
129 .\"O on the strings \fI(*a)\->d_name\fP and \fI(*b)\->d_name\fP.
130 .BR alphasort ()
131 ¤Ï
132 .BR strcoll (3)
133 ¤òÍѤ¤¤Æ¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤ò¥½¡¼¥È¤·¡¢
134 .BR versionsort ()
135 ¤Ïʸ»úÎó \fI(*a)\->d_name\fP ¤È \fI(*b)\->d_name\fP ¤ËÂФ·¤Æ
136 .BR strverscmp (3)
137 ¤òÍѤ¤¤ë¡£
138 .\"O .SH "RETURN VALUE"
139 .SH ÊÖ¤êÃÍ
140 .\"O The
141 .\"O .BR scandir ()
142 .\"O function returns the number of directory entries
143 .\"O selected or \-1 if an error occurs.
144 ´Ø¿ô
145 .BR scandir ()
146 ¤ÏÁªÂò¤µ¤ì¤¿¥¨¥ó¥È¥ê¤Î¿ô¤«¡¢
147 (¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç) \-1 ¤òÊÖ¤¹¡£
148 .PP
149 .\"O The
150 .\"O .BR alphasort ()
151 .\"O and
152 .\"O .BR versionsort ()
153 .\"O functions return an integer less than, equal to,
154 .\"O or greater than zero if the first argument is considered to be
155 .\"O respectively less than, equal to, or greater than the second.
156 ´Ø¿ô
157 .BR alphasort ()
158 ¤È
159 .BR versionsort ()
160 ¤Ï 1 ÈÖÌܤΰú¤­¿ô¤¬ 2 ÈÖÌܤΰú¤­¿ô¤ËÂФ·¤Æ¡¢
161 [¾®¤µ¤¤/Åù¤·¤¤/Â礭¤¤] ¤«¤Ë±þ¤¸¤Æ¡¢0 ¤è¤ê [¾®¤µ¤¤/Åù¤·¤¤/Â礭¤¤] ÃͤòÊÖ¤¹¡£
162 .\"O .SH ERRORS
163 .SH ¥¨¥é¡¼
164 .TP
165 .B ENOMEM
166 .\"O Insufficient memory to complete the operation.
167 Æ°ºî¤ò´°¿ë¤¹¤ë¤Ë¤Ï¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
168 .\"O .SH VERSIONS
169 .SH ¥Ð¡¼¥¸¥ç¥ó
170 .\"O .BR versionsort ()
171 .\"O was added to glibc in version 2.1.
172 .BR versionsort ()
173 ¤Ï¡¢glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤ÇÄɲ䵤줿¡£
174 .\"O .SH "CONFORMING TO"
175 .SH ½àµò
176 .\"O .BR alphasort ()
177 .\"O and
178 .\"O .BR scandir ()
179 .\"O are specified in POSIX.1-2008, and are widely available.
180 .\"O .BR versionsort ()
181 .\"O is a GNU extension.
182 .BR alphasort ()
183 ¤È
184 .BR scandir ()
185 ¤Ï POSIX.1-2008 ¤Çµ¬Äꤵ¤ì¤Æ¤ª¤ê¡¢¹­¤¯ÍøÍѲÄǽ¤Ç¤¢¤ë¡£
186 .BR versionsort ()
187 ¤Ï GNU ³ÈÄ¥¤Ç¤¢¤ë¡£
188 .LP
189 .\"O The functions
190 .\"O .BR scandir ()
191 .\"O and
192 .\"O .BR alphasort ()
193 .\"O are from 4.3BSD, and have been available under Linux since libc4.
194 ´Ø¿ô
195 .BR scandir ()
196 ¤È
197 .BR alphasort ()
198 ¤Ï 4.3BSD ¤«¤é¼è¤êÆþ¤ì¤é¤ì¡¢Linux ¤Ç¤Ï libc4 ¤«¤é»ÈÍѲÄǽ¤Ë¤Ê¤Ã¤¿¡£
199 .\"O Libc4 and libc5 use the more precise prototype
200 libc4 ¤È libc5 ¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ê¤â¤Ã¤È¾ÜºÙ¤Ê¥×¥í¥È¥¿¥¤¥×¤ò»È¤Ã¤Æ¤¤¤ë¡£
201 .sp
202 .nf
203     int alphasort(const struct dirent ** a,
204                   const struct dirent **b);
205 .fi
206 .sp
207 .\"O but glibc 2.0 returns to the imprecise BSD prototype.
208 ¤·¤«¤· glibc 2.0 ¤Ç¤ÏÉÔÀµ³Î¤Ê BSD ¤Î¥×¥í¥È¥¿¥¤¥×¤ËÌá¤Ã¤¿¡£
209 .LP
210 .\"O The function
211 .\"O .BR versionsort ()
212 .\"O is a GNU extension, available since glibc 2.1.
213 ´Ø¿ô
214 .BR versionsort ()
215 ¤Ï GNU ¤Î³ÈÄ¥¤Ç¤¢¤ê¡¢glibc 2.1 °Ê¹ß¤Ç»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
216 .LP
217 .\"O Since glibc 2.1,
218 .\"O .BR alphasort ()
219 .\"O calls
220 .\"O .BR strcoll (3);
221 .\"O earlier it used
222 .\"O .BR strcmp (3).
223 glibc 2.1 °Ê¹ß¤Ç¤Ï
224 .BR alphasort ()
225 ¤Ï
226 .BR strcoll (3)
227 ¤ò¸Æ¤Ó½Ð¤¹¡£
228 .BR alphasort ()
229 ¤Ï°ÊÁ°¤Ï
230 .BR strcmp (3)
231 ¤ò»È¤Ã¤Æ¤¤¤¿¡£
232 .\"O .SH EXAMPLE
233 .SH Îã
234 .nf
235 #define _SVID_SOURCE
236 .\"O /* print files in current directory in reverse order */
237 /* ¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Õ¥¡¥¤¥ë¤òµÕ½ç¤Ë½ÐÎϤ¹¤ë */
238 #include <dirent.h>
239
240 int
241 main(void)
242 {
243     struct dirent **namelist;
244     int n;
245
246     n = scandir(".", &namelist, 0, alphasort);
247     if (n < 0)
248         perror("scandir");
249     else {
250         while (n\-\-) {
251             printf("%s\en", namelist[n]\->d_name);
252             free(namelist[n]);
253         }
254         free(namelist);
255     }
256 }
257 .fi
258 .\"O .SH "SEE ALSO"
259 .SH ´ØÏ¢¹àÌÜ
260 .BR closedir (3),
261 .BR fnmatch (3),
262 .BR opendir (3),
263 .BR readdir (3),
264 .BR rewinddir (3),
265 .BR seekdir (3),
266 .BR strcmp (3),
267 .BR strcoll (3),
268 .BR strverscmp (3),
269 .BR telldir (3)