2 .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SCANDIR 3C "May 4, 2004"
8 scandir, alphasort \- scan a directory
12 #include <sys/types.h>
15 \fBint\fR \fBscandir\fR(\fBconst char *\fR\fIdirname\fR, \fBstruct dirent *\fR(*\fInamelist\fR[]),
16 \fBint\fR (*\fIselect\fR)(const struct dirent *),
17 \fBint\fR (*\fIdcomp\fR)(\fBconst struct dirent **\fR,
18 \fBconst struct dirent **\fR));
23 \fBint\fR \fBalphasort\fR(\fBconst struct dirent **\fR\fId1\fR,
24 \fBconst struct dirent **\fR\fId2\fR);
30 The \fBscandir()\fR function reads the directory \fIdirname\fR using
31 \fBreaddir\fR(3C) and builds an array of pointers to directory entries using
32 \fBmalloc\fR(3C). The \fInamelist\fR argument is a pointer to an array of
33 structure pointers. The \fIselect\fR argument is a pointer to a routine that is
34 called with a pointer to a directory entry and returns a non-zero value if the
35 directory entry is included in the array. If this pointer is \fINULL\fR, then
36 all the directory entries are included. The \fIdcomp\fR argument is a pointer
37 to a routine that is passed to \fBqsort\fR(3C), which sorts the completed
38 array. If this pointer is \fINULL\fR, the array is not sorted.
41 The \fBalphasort()\fR function can be used as the \fIdcomp\fR() function
42 parameter for the \fBscandir()\fR function to sort the directory entries into
43 alphabetical order, as if by the \fBstrcoll\fR(3C) function. Its arguments are
44 the two directory entries to compare.
48 The \fBscandir()\fR function returns the number of entries in the array and a
49 pointer to the array through the \fInamelist\fR argument. When an error is
50 encountered, \fBscandir()\fR returns -1 and \fBerrno\fR is set to indicate the
54 The \fBalphasort()\fR function returns an integer greater than, equal to, or
55 less than 0 if the directory entry name pointed to by \fId1\fR is greater than,
56 equal to, or less than the directory entry name pointed to by \fId2\fR when
57 both are interpreted as appropriate to the current locale. There is no return
58 value reserved to indicate an error.
62 The \fBscandir()\fR function will fail if:
69 The number of directory entries exceeds the number that can be represented by
76 The \fBscandir()\fR and \fBalphasort()\fR functions have transitional
77 interfaces for 64-bit file offsets. See \fBlf64\fR(5).
81 See \fBattributes\fR(5) for descriptions of the following attributes:
89 ATTRIBUTE TYPE ATTRIBUTE VALUE
91 Interface Stability Stable
98 The \fBscandir()\fR function is Unsafe. The \fBalphasort()\fR function is Safe.
102 \fBmalloc\fR(3C), \fBqsort\fR(3C), \fBreaddir\fR(3C), \fBstrcoll\fR(3C),
103 \fBattributes\fR(5), \fBlf64\fR(5)