1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" References consulted:
.\" Linux libc source code
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
.\" 386BSD man pages
.\" Modified Sat Jul 24 18:26:16 1993 by Rik Faith (faith@cs.unc.edu)
.\" Modified Thu Apr 11 17:11:33 1996 by Andries Brouwer (aeb@cwi.nl):
.\" Corrected type of compar routines, as suggested by
.\" Miguel Barreiro (enano@avalon.yaix.es). Added example.
.\" Modified Sun Sep 24 20:15:46 2000 by aeb, following Petter Reinholdtsen.
.\" Modified 2001-12-26 by aeb, following Joey. Added versionsort.
.\"
.\" Japanese Version Copyright (c) 1998 Hiroaki Nagoya all rights reserved.
.\" Translated Thu May 28 1998 by Hiroaki Nagoya <nagoya@is.titech.ac.jp>
.\" Updated & Modified Sat Jan 19 18:22:21 JST 2002
.\" by Yuichi SATO <ysato@h4.dion.ne.jp>
.\" Updated & Modified Sun Jan 16 08:12:04 JST 2005
.\" by Yuichi SATO <ysato444@yahoo.co.jp>
.\"
.TH SCANDIR 3 2009-02-10 "GNU" "Linux Programmer's Manual"
.SH ̾
scandir, alphasort, versionsort \- ǥ쥯ȥ
.SH
.nf
.B #include <dirent.h>
.sp
.BI "int scandir(const char *" dirp ", struct dirent ***" namelist ,
.RS
.BI "int (*" filter ")(const struct dirent *),"
.BI "int (*" compar ")(const struct dirent **, const struct dirent **));"
.RE
.sp
.BI "int alphasort(const void *" a ", const void *" b );
.sp
.BI "int versionsort(const void *" a ", const void *" b );
.fi
.sp
.in -4n
glibc εǽޥ
.RB ( feature_test_macros (7)
):
.in
.sp
.BR scandir (),
.BR alphasort ():
_BSD_SOURCE || _SVID_SOURCE
.br
.BR versionsort ():
_GNU_SOURCE
.SH
ؿ
.BR scandir ()
ϥǥ쥯ȥ \fIdirp\fP
ǥ쥯ȥγƥȥȤ
.BR filter ()
ƤӽФ
.BR filter ()
0 ʳ֤ͤȥ
.BR malloc (3)
ˤä
ݤ줿ʸ¸졢Ӵؿ
.BR compar ()
Ѥ
.BR qsort (3)
ˤȤ졢
.BR malloc (3)
ˤݤ줿
\fInamelist\fP ˤޤȤ롣
\fIfilter\fP NULL ʤС٤ƤΥȥ꤬롣
.LP
Ӵؿ
.IR compar ()
ˤ
.BR alphasort ()
ؿ
.BR versionsort ()
ؿȤȤǤ롣
.BR alphasort ()
.BR strcoll (3)
Ѥƥǥ쥯ȥꥨȥȤ
.BR versionsort ()
ʸ \fI(*a)\->d_name\fP \fI(*b)\->d_name\fP Ф
.BR strverscmp (3)
Ѥ롣
.SH ֤
ؿ
.BR scandir ()
줿ȥο
(顼ȯ) \-1 ֤
.PP
ؿ
.BR alphasort ()
.BR versionsort ()
1 ܤΰ 2 ܤΰФơ
[//礭] ˱ơ0 [//礭] ֤ͤ
.SH 顼
.TP
.B ENOMEM
ư뤹ˤϥ꤬ʤ
.SH С
.BR versionsort ()
ϡglibc С 2.1 ɲä줿
.SH
.BR alphasort ()
.BR scandir ()
POSIX.1-2008 ǵꤵƤꡢѲǽǤ롣
.BR versionsort ()
GNU ĥǤ롣
.LP
ؿ
.BR scandir ()
.BR alphasort ()
4.3BSD 졢Linux Ǥ libc4 Ѳǽˤʤä
libc4 libc5 ǤϰʲΤ褦ʤäȾܺ٤ʥץȥפȤäƤ롣
.sp
.nf
int alphasort(const struct dirent ** a,
const struct dirent **b);
.fi
.sp
glibc 2.0 ǤΤ BSD Υץȥפä
.LP
ؿ
.BR versionsort ()
GNU γĥǤꡢglibc 2.1 ʹߤǻѲǽǤ롣
.LP
glibc 2.1 ʹߤǤ
.BR alphasort ()
.BR strcoll (3)
ƤӽФ
.BR alphasort ()
ϰ
.BR strcmp (3)
ȤäƤ
.SH
.nf
#define _SVID_SOURCE
/* ȥǥ쥯ȥΥես˽Ϥ */
#include <dirent.h>
int
main(void)
{
struct dirent **namelist;
int n;
n = scandir(".", &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else {
while (n\-\-) {
printf("%s\en", namelist[n]\->d_name);
free(namelist[n]);
}
free(namelist);
}
}
.fi
.SH Ϣ
.BR closedir (3),
.BR fnmatch (3),
.BR opendir (3),
.BR readdir (3),
.BR rewinddir (3),
.BR seekdir (3),
.BR strcmp (3),
.BR strcoll (3),
.BR strverscmp (3),
.BR telldir (3)
|