OSDN Git Service

(split) Apply minor changes from v3.32 to v3.35 in the upstream.
[linuxjm/LDP_man-pages.git] / release / 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 .\" FIXME glibc 2.15 adds scandirat()
35 .\"
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>
42 .\"
43 .TH SCANDIR 3  2011-09-08 "GNU" "Linux Programmer's Manual"
44 .SH Ì¾Á°
45 scandir, alphasort, versionsort \- ¥Ç¥£¥ì¥¯¥È¥ê¤òÁöºº¤¹¤ë
46 .SH ½ñ¼°
47 .nf
48 .B #include <dirent.h>
49 .sp
50 .BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
51 .RS
52 .BI "int (*" filter ")(const struct dirent *),"
53 .BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
54 .RE
55 .sp
56 .BI "int alphasort(const void *" a ", const void *" b );
57 .sp
58 .BI "int versionsort(const void *" a ", const void *" b );
59 .fi
60 .sp
61 .in -4n
62 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
63 .RB ( feature_test_macros (7)
64 »²¾È):
65 .in
66 .sp
67 .BR scandir (),
68 .BR alphasort ():
69 _BSD_SOURCE || _SVID_SOURCE
70 .br
71 .BR versionsort ():
72 _GNU_SOURCE
73 .SH ÀâÌÀ
74 ´Ø¿ô
75 .BR scandir ()
76 ¤Ï¥Ç¥£¥ì¥¯¥È¥ê \fIdirp\fP ¤òÁöºº¤·¡¢
77 ¥Ç¥£¥ì¥¯¥È¥ê¤Î³Æ¥¨¥ó¥È¥ê¤ò°ú¤­¿ô¤È¤·¤Æ
78 .BR filter ()
79 ¤ò¸Æ¤Ó½Ð¤¹¡£
80 .BR filter ()
81 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¥¨¥ó¥È¥ê¤Ï
82 .BR malloc (3)
83 ¤Ë¤è¤Ã¤Æ
84 ³ÎÊݤµ¤ì¤¿Ê¸»úÎó¤ËÊݸ¤µ¤ì¡¢Èæ³Ó´Ø¿ô
85 .BR compar ()
86 ¤òÍѤ¤¤Æ
87 .BR qsort (3)
88 ¤Ë¤è¤ê¥½¡¼¥È¤µ¤ì¡¢
89 .BR malloc (3)
90 ¤Ë¤è¤ê³ÎÊݤµ¤ì¤¿ÇÛÎó
91 \fInamelist\fP ¤Ë¤Þ¤È¤á¤é¤ì¤ë¡£
92 \fIfilter\fP ¤¬ NULL ¤Ê¤é¤Ð¡¢¤¹¤Ù¤Æ¤Î¥¨¥ó¥È¥ê¤¬ÁªÂò¤µ¤ì¤ë¡£
93 .LP
94 Èæ³Ó´Ø¿ô
95 .IR compar ()
96 ¤Ë¤Ï
97 .BR alphasort ()
98 ´Ø¿ô¤È
99 .BR versionsort ()
100 ´Ø¿ô¤ò»È¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
101 .BR alphasort ()
102 ¤Ï
103 .BR strcoll (3)
104 ¤òÍѤ¤¤Æ¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤ò¥½¡¼¥È¤·¡¢
105 .BR versionsort ()
106 ¤Ïʸ»úÎó \fI(*a)\->d_name\fP ¤È \fI(*b)\->d_name\fP ¤ËÂФ·¤Æ
107 .BR strverscmp (3)
108 ¤òÍѤ¤¤ë¡£
109 .SH ÊÖ¤êÃÍ
110 ´Ø¿ô
111 .BR scandir ()
112 ¤ÏÁªÂò¤µ¤ì¤¿¥¨¥ó¥È¥ê¤Î¿ô¤«¡¢
113 (¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç) \-1 ¤òÊÖ¤¹¡£
114 .PP
115 ´Ø¿ô
116 .BR alphasort ()
117 ¤È
118 .BR versionsort ()
119 ¤Ï 1 ÈÖÌܤΰú¤­¿ô¤¬ 2 ÈÖÌܤΰú¤­¿ô¤ËÂФ·¤Æ¡¢
120 [¾®¤µ¤¤/Åù¤·¤¤/Â礭¤¤] ¤«¤Ë±þ¤¸¤Æ¡¢0 ¤è¤ê [¾®¤µ¤¤/Åù¤·¤¤/Â礭¤¤] ÃͤòÊÖ¤¹¡£
121 .SH ¥¨¥é¡¼
122 .TP
123 .B ENOENT
124 \fIdirp\fR ¤Ç»ØÄꤵ¤ì¤¿¥Ñ¥¹¤¬Â¸ºß¤·¤Ê¤¤¡£
125 .TP
126 .B ENOMEM
127 Æ°ºî¤ò´°¿ë¤¹¤ë¤Ë¤Ï¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
128 .TP
129 .B ENOTDIR
130 \fIdirp\fR ¤Ç»ØÄꤵ¤ì¤¿¥Ñ¥¹¤¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¡£
131 .SH ¥Ð¡¼¥¸¥ç¥ó
132 .BR versionsort ()
133 ¤Ï¡¢glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤ÇÄɲ䵤줿¡£
134 .SH ½àµò
135 .BR alphasort ()
136 ¤È
137 .BR scandir ()
138 ¤Ï POSIX.1-2008 ¤Çµ¬Äꤵ¤ì¤Æ¤ª¤ê¡¢¹­¤¯ÍøÍѲÄǽ¤Ç¤¢¤ë¡£
139 .BR versionsort ()
140 ¤Ï GNU ³ÈÄ¥¤Ç¤¢¤ë¡£
141 .LP
142 ´Ø¿ô
143 .BR scandir ()
144 ¤È
145 .BR alphasort ()
146 ¤Ï 4.3BSD ¤«¤é¼è¤êÆþ¤ì¤é¤ì¡¢Linux ¤Ç¤Ï libc4 ¤«¤é»ÈÍѲÄǽ¤Ë¤Ê¤Ã¤¿¡£
147 libc4 ¤È libc5 ¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ê¤â¤Ã¤È¾ÜºÙ¤Ê¥×¥í¥È¥¿¥¤¥×¤ò»È¤Ã¤Æ¤¤¤ë¡£
148 .sp
149 .nf
150     int alphasort(const struct dirent ** a,
151                   const struct dirent **b);
152 .fi
153 .sp
154 ¤·¤«¤· glibc 2.0 ¤Ç¤ÏÉÔÀµ³Î¤Ê BSD ¤Î¥×¥í¥È¥¿¥¤¥×¤ËÌá¤Ã¤¿¡£
155 .LP
156 ´Ø¿ô
157 .BR versionsort ()
158 ¤Ï GNU ¤Î³ÈÄ¥¤Ç¤¢¤ê¡¢glibc 2.1 °Ê¹ß¤Ç»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
159 .LP
160 glibc 2.1 °Ê¹ß¤Ç¤Ï
161 .BR alphasort ()
162 ¤Ï
163 .BR strcoll (3)
164 ¤ò¸Æ¤Ó½Ð¤¹¡£
165 .BR alphasort ()
166 ¤Ï°ÊÁ°¤Ï
167 .BR strcmp (3)
168 ¤ò»È¤Ã¤Æ¤¤¤¿¡£
169 .SH Îã
170 .nf
171 #define _SVID_SOURCE
172 /* ¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Õ¥¡¥¤¥ë¤òµÕ½ç¤Ë½ÐÎϤ¹¤ë */
173 #include <dirent.h>
174
175 int
176 main(void)
177 {
178     struct dirent **namelist;
179     int n;
180
181     n = scandir(".", &namelist, 0, alphasort);
182     if (n < 0)
183         perror("scandir");
184     else {
185         while (n\-\-) {
186             printf("%s\en", namelist[n]\->d_name);
187             free(namelist[n]);
188         }
189         free(namelist);
190     }
191 }
192 .fi
193 .SH ´ØÏ¢¹àÌÜ
194 .BR closedir (3),
195 .BR fnmatch (3),
196 .BR opendir (3),
197 .BR readdir (3),
198 .BR rewinddir (3),
199 .BR seekdir (3),
200 .BR strcmp (3),
201 .BR strcoll (3),
202 .BR strverscmp (3),
203 .BR telldir (3)