Print this page
Ensured various XPG7 stuff are declared properly in sys/stat.h (and cleanup)
New documentation for wcslen, wcsnlen, wcscasecmp (and friends), wcsdup.
Various other tweaks and markup improvements.
Various tweaks -- add our sections, etc.
More markup tweaks.
alphasort and scandir are new in XPG7

@@ -1,103 +1,130 @@
-'\" te
+.\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
 .\" Copyright (c) 2004, 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 3C "May 4, 2004"
-.SH NAME
-scandir, alphasort \- scan a directory
-.SH SYNOPSIS
-.LP
-.nf
-#include <sys/types.h>
-#include <dirent.h>
-
-\fBint\fR \fBscandir\fR(\fBconst char *\fR\fIdirname\fR, \fBstruct dirent *\fR(*\fInamelist\fR[]),
-     \fBint\fR (*\fIselect\fR)(const struct dirent *),
-     \fBint\fR (*\fIdcomp\fR)(\fBconst struct dirent  **\fR,
-     \fBconst struct dirent **\fR));
-.fi
-
-.LP
-.nf
-\fBint\fR \fBalphasort\fR(\fBconst struct dirent **\fR\fId1\fR,
-     \fBconst struct dirent **\fR\fId2\fR);
-.fi
-
-.SH DESCRIPTION
-.sp
-.LP
-The \fBscandir()\fR function reads the directory \fIdirname\fR using
-\fBreaddir\fR(3C) and builds an array of pointers to directory entries using
-\fBmalloc\fR(3C). The \fInamelist\fR argument is a pointer to an array of
-structure pointers. The \fIselect\fR argument is a pointer to a routine that is
+.Dd "Jul 22, 2014"
+.Dt SCANDIR 3C
+.Os
+.Sh NAME
+.Nm scandir ,
+.Nm alphasort
+.Nd scan a directory
+.Sh SYNOPSIS
+.In dirent.h
+.
+.Ft int
+.Fo scandir
+.Fa "const char *dirname"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp*dcomp\*(rp\*(lpconst struct dirent  **, const struct dirent **\*(rp"
+.Fc
+.
+.Ft int
+.Fn alphasort "const struct dirent **d1" "const struct dirent **d2"
+.
+.Sh DESCRIPTION
+The
+.Fn scandir
+function reads the directory
+.Fa dirname
+using
+.Xr readdir 3C
+and builds an array of pointers to directory entries using
+.Xr malloc 3C .
+The
+.Fa namelist
+argument is a pointer to an array of
+structure pointers. The
+.Fa select
+argument is a pointer to a routine that is
 called with a pointer to a directory entry and returns a non-zero value if the
-directory entry is included in the array. If this pointer is \fINULL\fR, then
-all the directory entries are included. The \fIdcomp\fR argument is a pointer
-to a routine that 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 can be used as the \fIdcomp\fR() function
-parameter for the \fBscandir()\fR function to sort the directory entries into
-alphabetical order, as if by the \fBstrcoll\fR(3C) function. Its arguments are
+directory entry is included in the array. If this pointer is
+.Dv NULL ,
+then
+all the directory entries are included. The
+.Fa dcomp
+argument is a pointer
+to a routine that is passed to
+.Xr qsort 3C ,
+which sorts the completed array. If this pointer is
+.Dv NULL ,
+the array is not sorted.
+.Lp
+The
+.Fn alphasort
+function can be used as the
+.Fn dcomp
+function parameter for the
+.Fn scandir
+function to sort the directory entries into
+alphabetical order, as if by the
+.Xr strcoll 3C
+function. Its arguments are
 the two directory entries to compare.
-.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 \fInamelist\fR argument. When an error is
-encountered, \fBscandir()\fR returns -1 and \fBerrno\fR is set to indicate the
-error.
-.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 when
+.Sh RETURN VALUES
+The
+.Fn scandir
+function returns the number of entries in the array and a
+pointer to the array through the
+.Fa namelist
+argument. When an error is
+encountered,
+.Fn scandir
+returns -1 and
+.Va errno
+is set to indicate the error.
+.Lp
+The
+.Fn alphasort
+function returns an integer greater than, equal to, or
+less than 0 if the directory entry name pointed to by
+.Fa d1
+is greater than, equal to, or less than the directory entry name pointed to by
+.Fa d2
+when
 both are interpreted as appropriate to the current locale. There is no return
 value reserved to indicate an error.
-.SH ERRORS
-.sp
-.LP
-The \fBscandir()\fR function will fail if:
-.sp
-.ne 2
-.na
-\fB\fBEOVERFLOW\fR\fR
-.ad
-.RS 13n
+.Sh ERRORS
+The
+.Fn scandir
+function will fail if:
+.Bl -tag -width Er
+.It Er EOVERFLOW
 The number of directory entries exceeds the number that can be represented by
-an \fBint\fR.
-.RE
-
-.SH USAGE
-.sp
-.LP
-The \fBscandir()\fR and \fBalphasort()\fR functions have transitional
-interfaces for 64-bit file offsets. See \fBlf64\fR(5).
-.SH ATTRIBUTES
-.sp
-.LP
-See \fBattributes\fR(5) for descriptions of the following attributes:
-.sp
-
-.sp
-.TS
-box;
-c | c
-l | l .
-ATTRIBUTE TYPE  ATTRIBUTE VALUE
-_
-Interface Stability     Stable
-_
-MT-Level        See below.
-.TE
-
-.sp
-.LP
-The \fBscandir()\fR function is Unsafe. The \fBalphasort()\fR function is Safe.
-.SH SEE ALSO
-.sp
-.LP
-\fBmalloc\fR(3C), \fBqsort\fR(3C), \fBreaddir\fR(3C), \fBstrcoll\fR(3C),
-\fBattributes\fR(5), \fBlf64\fR(5)
+an
+.Vt int .
+.El
+.Sh USAGE
+The
+.Fn scandir
+and
+.Fn alphasort
+functions have transitional interfaces for 64-bit file offsets. See
+.Xr lf64 5 .
+.Sh INTERFACE STABILITY
+.Sy Standard .
+.Sh MT-LEVEL
+The
+.Fn scandir
+function is
+.Sy Unsafe .
+The
+.Fn alphasort
+function is
+.Sy Safe .
+.Sh SEE ALSO
+.Xr malloc 3C ,
+.Xr qsort 3C ,
+.Xr readdir 3C ,
+.Xr strcoll 3C ,
+.Xr lf64 5 ,
+.Xr standards 5
+.Sh STANDARDS
+The
+.Fn alphasort
+and
+.Fn scandir
+functions were introduced in
+.St -p1003.1-2008 .