1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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.
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>
41 .TH SCANDIR 3 2009-02-10 "GNU" "Linux Programmer's Manual"
44 .\"O scandir, alphasort, versionsort \- scan a directory for matching entries
45 scandir, alphasort, versionsort \- ¥Ç¥£¥ì¥¯¥È¥ê¤òÁöºº¤¹¤ë
49 .B #include <dirent.h>
51 .BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
53 .BI "int (*" filter ")(const struct dirent *),"
54 .BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
57 .BI "int alphasort(const void *" a ", const void *" b );
59 .BI "int versionsort(const void *" a ", const void *" b );
63 .\"O Feature Test Macro Requirements for glibc (see
64 .\"O .BR feature_test_macros (7)):
65 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
66 .RB ( feature_test_macros (7)
72 _BSD_SOURCE || _SVID_SOURCE
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
87 .\"O with the comparison
88 .\"O function \fIcompar\fP() and collected in array \fInamelist\fP
89 .\"O which is allocated via
91 .\"O If \fIfilter\fP is NULL, all entries are selected.
94 ¤Ï¥Ç¥£¥ì¥¯¥È¥ê \fIdirp\fP ¤òÁöºº¤·¡¢
95 ¥Ç¥£¥ì¥¯¥È¥ê¤Î³Æ¥¨¥ó¥È¥ê¤ò°ú¤¿ô¤È¤·¤Æ
99 ¤¬ 0 °Ê³°¤ÎÃͤòÊÖ¤¹¥¨¥ó¥È¥ê¤Ï
102 ³ÎÊݤµ¤ì¤¿Ê¸»úÎó¤ËÊݸ¤µ¤ì¡¢Èæ³Ó´Ø¿ô
109 \fInamelist\fP ¤Ë¤Þ¤È¤á¤é¤ì¤ë¡£
110 \fIfilter\fP ¤¬ NULL ¤Ê¤é¤Ð¡¢¤¹¤Ù¤Æ¤Î¥¨¥ó¥È¥ê¤¬ÁªÂò¤µ¤ì¤ë¡£
113 .\"O .BR alphasort ()
115 .\"O .BR versionsort ()
116 .\"O functions can be used as the comparison function
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.
133 ¤òÍѤ¤¤Æ¥Ç¥£¥ì¥¯¥È¥ê¥¨¥ó¥È¥ê¤ò¥½¡¼¥È¤·¡¢
135 ¤Ïʸ»úÎó \fI(*a)\->d_name\fP ¤È \fI(*b)\->d_name\fP ¤ËÂФ·¤Æ
138 .\"O .SH "RETURN VALUE"
142 .\"O function returns the number of directory entries
143 .\"O selected or \-1 if an error occurs.
146 ¤ÏÁªÂò¤µ¤ì¤¿¥¨¥ó¥È¥ê¤Î¿ô¤«¡¢
147 (¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç) \-1 ¤òÊÖ¤¹¡£
150 .\"O .BR alphasort ()
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.
160 ¤Ï 1 ÈÖÌܤΰú¤¿ô¤¬ 2 ÈÖÌܤΰú¤¿ô¤ËÂФ·¤Æ¡¢
161 [¾®¤µ¤¤/Åù¤·¤¤/Â礤¤] ¤«¤Ë±þ¤¸¤Æ¡¢0 ¤è¤ê [¾®¤µ¤¤/Åù¤·¤¤/Â礤¤] ÃͤòÊÖ¤¹¡£
166 .\"O Insufficient memory to complete the operation.
167 Æ°ºî¤ò´°¿ë¤¹¤ë¤Ë¤Ï¥á¥â¥ê¤¬Â¤ê¤Ê¤¤¡£
170 .\"O .BR versionsort ()
171 .\"O was added to glibc in version 2.1.
173 ¤Ï¡¢glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤ÇÄɲ䵤줿¡£
174 .\"O .SH "CONFORMING TO"
176 .\"O .BR alphasort ()
179 .\"O are specified in POSIX.1-2008, and are widely available.
180 .\"O .BR versionsort ()
181 .\"O is a GNU extension.
185 ¤Ï POSIX.1-2008 ¤Çµ¬Äꤵ¤ì¤Æ¤ª¤ê¡¢¹¤¯ÍøÍѲÄǽ¤Ç¤¢¤ë¡£
192 .\"O .BR alphasort ()
193 .\"O are from 4.3BSD, and have been available under Linux since libc4.
198 ¤Ï 4.3BSD ¤«¤é¼è¤êÆþ¤ì¤é¤ì¡¢Linux ¤Ç¤Ï libc4 ¤«¤é»ÈÍѲÄǽ¤Ë¤Ê¤Ã¤¿¡£
199 .\"O Libc4 and libc5 use the more precise prototype
200 libc4 ¤È libc5 ¤Ç¤Ï°Ê²¼¤Î¤è¤¦¤Ê¤â¤Ã¤È¾ÜºÙ¤Ê¥×¥í¥È¥¿¥¤¥×¤ò»È¤Ã¤Æ¤¤¤ë¡£
203 int alphasort(const struct dirent ** a,
204 const struct dirent **b);
207 .\"O but glibc 2.0 returns to the imprecise BSD prototype.
208 ¤·¤«¤· glibc 2.0 ¤Ç¤ÏÉÔÀµ³Î¤Ê BSD ¤Î¥×¥í¥È¥¿¥¤¥×¤ËÌá¤Ã¤¿¡£
211 .\"O .BR versionsort ()
212 .\"O is a GNU extension, available since glibc 2.1.
215 ¤Ï GNU ¤Î³ÈÄ¥¤Ç¤¢¤ê¡¢glibc 2.1 °Ê¹ß¤Ç»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
217 .\"O Since glibc 2.1,
218 .\"O .BR alphasort ()
220 .\"O .BR strcoll (3);
236 .\"O /* print files in current directory in reverse order */
237 /* ¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Õ¥¡¥¤¥ë¤òµÕ½ç¤Ë½ÐÎϤ¹¤ë */
243 struct dirent **namelist;
246 n = scandir(".", &namelist, 0, alphasort);
251 printf("%s\en", namelist[n]\->d_name);