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
|
'\" te
.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
.\" 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. 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. 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]
.TH SCANDIR 3UCB "Oct 30, 2007"
.SH NAME
scandir, alphasort \- scan a directory
.SH SYNOPSIS
.LP
.nf
\fB/usr/ucb/cc\fR [ \fIflag\fR... ] \fIfile\fR...
#include <sys/types.h>
#include <sys/dir.h>
\fBint\fR \fBscandir\fR(\fIdirname\fR, \fInamelist\fR, \fIselect\fR, \fIdcomp\fR)
\fBchar *\fR\fIdirname\fR;
\fBstruct direct *\fR(*\fInamelist\fR[]);
\fBint\fR (\fB*\fR\fIselect\fR(), (\fB*\fR\fIdcomp\fR)();
.fi
.LP
.nf
\fBint\fR \fBalphasort\fR(\fId1\fR, \fId2\fR)
\fBstruct direct **\fR\fId1\fR, \fB**\fR\fId2\fR;
.fi
.SH DESCRIPTION
.sp
.LP
The \fBscandir()\fR function reads the directory \fIdirname\fR and builds an
array of pointers to directory entries using \fBmalloc\fR(3C). The second
parameter is a pointer to an array of structure pointers. The third parameter
is a pointer to a routine which is called with a pointer to a directory entry
and should return a non zero value if the directory entry should be included in
the array. If this pointer is \fINULL\fR, then all the directory entries will
be included. The last argument is a pointer to a routine which is passed to
\fBqsort\fR(3C), which sorts the completed array. If this pointer is
\fINULL\fR, the array is not sorted.
.sp
.LP
The \fBalphasort()\fR function sorts the array alphabetically.
.SH RETURN VALUES
.sp
.LP
The \fBscandir()\fR function returns the number of entries in the array and a
pointer to the array through the parameter \fInamelist\fR. The \fBscandir()\fR
function returns \fB\(mi1\fR if the directory cannot be opened for reading or
if \fBmalloc\fR(3C) cannot allocate enough memory to hold all the data
structures.
.sp
.LP
The \fBalphasort()\fR function returns an integer greater than, equal to, or
less than 0 if the directory entry name pointed to by \fId1\fR is greater than,
equal to, or less than the directory entry name pointed to by \fId2\fR.
.SH USAGE
.sp
.LP
The \fBscandir()\fR and \fBalphasort()\fR functions have transitional
interfaces for 64-bit file offsets. See \fBlf64\fR(5).
.SH SEE ALSO
.sp
.LP
\fBgetdents\fR(2), \fBmalloc\fR(3C), \fBqsort\fR(3C), \fBreaddir\fR(3UCB),
\fBreaddir\fR(3C), \fBlf64\fR(5)
.SH NOTES
.sp
.LP
Use of these functions should be restricted to applications written on
\fBBSD\fR platforms. Use of these functions with any of the system libraries
or in multithreaded applications is unsupported.
|