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
|
.\" 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>
.\"
.TH SCANDIR 3 2001-12-26 "GNU" "Linux Programmer's Manual"
.SH ̾
scandir, alphasort, versionsort \- ǥ쥯ȥ
.SH
.nf
.B #include <dirent.h>
.sp
.BI "int scandir(const char *" dir ", struct dirent ***" namelist ,
.RS
.BI "int(*" select ")(const struct dirent *),"
.BI "int(*" compar ")(const struct dirent **, const struct dirent **));"
.RE
.sp
.BI "int alphasort(const void *" a ", const void *" b );
.br
.BI "int versionsort(const void *" a ", const void *" b );
.fi
.SH
ؿ \fBscandir()\fP ϥǥ쥯ȥ \fIdir\fP
ǥ쥯ȥγƥȥȤ \fIselect()\fP ƤӽФ
\fIselect()\fP 0 ʳ֤ͤȥ \fBmalloc()\fP ˤä
ݤ줿ʸ¸졢Ӵؿ \fIcompar()\fP Ѥ
\fBqsort()\fP ˤȤ졢\fBmalloc()\fP ˤݤ줿
\fInamelist\fP ˤޤȤ롣
\fIselect\fP NULL ʤС٤ƤΥȥ꤬롣
.LP
Ӵؿ
.I compar()
ˤ
.B alphasort()
ؿ
.B versionsort()
ؿȤȤǤ롣
Ԥ
.BR strcoll (3)
Ѥƥǥ쥯ȥꥨȥȤ
Ԥʸ \fI(*a)->d_name\fP \fI(*b)->d_name\fP Ф
.BR strvers\%cmp (3)
Ѥ롣
.SH ֤
ؿ \fBscandir()\fP 줿ȥο
(顼ȯ) \-1 ֤
.PP
ؿ
.B alphasort()
.B versionsort()
1 ܤΰ 2 ܤΰФơ
[//礭] ˱ơ0 [//礭] ֤ͤ
.SH 顼
.TP
.B ENOMEM
ư뤹ˤϥ꤬ʤ
.SH
δؿ POSIX ˤϤʤ
ؿ
.B scandir()
.B alphasort()
BSD 4.3 졢Linux Ǥ libc4 Ѳǽˤʤä
libc4 libc5 ǤϰʲΤ褦ʤäȾܺ٤ʥץȥפȤäƤ롣
.sp
.nf
.BI "int alphasort(const struct dirent **" a ", const struct dirent **" b );
.fi
.sp
glibc 2.0 ǤΤ BSD Υץȥפä
.LP
ؿ
.B versionsort()
GNU γĥǤꡢglibc 2.1 ʹߤǻѲǽǤ롣
glibc 2.1 ʹߤǤ
.B alphasort()
.BR strcoll (3)
ƤӽФ
.B alphasort()
ϰ
.BR strcmp (3)
ȤäƤ
.SH
.nf
/* ȥǥ쥯ȥΥես˽Ϥ */
#include <dirent.h>
main(){
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 opendir (3),
.BR readdir (3),
.BR rewinddir (3),
.BR seekdir (3),
.BR strcmp (3),
.BR strcoll (3),
.BR strverscmp (3),
.BR telldir (3)
|