OSDN Git Service

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