Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/scandir.3
Show All 22 Lines | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 | .\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd January 3, 2010 | .Dd July 11, 2022 | ||||
.Dt SCANDIR 3 | .Dt SCANDIR 3 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm scandir , | .Nm scandir , | ||||
.Nm alphasort | .Nm alphasort , | ||||
.Nm versionsort | |||||
.Nd scan a directory | .Nd scan a directory | ||||
.Sh LIBRARY | .Sh LIBRARY | ||||
.Lb libc | .Lb libc | ||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||
.In dirent.h | .In dirent.h | ||||
.Ft int | .Ft int | ||||
.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp" "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" | .Fn scandir "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp" "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" | ||||
.Ft int | .Ft int | ||||
.Fn scandir_b "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\^(rp\*(lpconst struct dirent *\*(rp" "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" | .Fn scandir_b "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\^(rp\*(lpconst struct dirent *\*(rp" "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" | ||||
.Ft int | .Ft int | ||||
.Fn alphasort "const struct dirent **d1" "const struct dirent **d2" | .Fn alphasort "const struct dirent **d1" "const struct dirent **d2" | ||||
.Ft int | |||||
.Fn versionsort "const struct dirent **d1" "const struct dirent **d2" | |||||
.Sh DESCRIPTION | .Sh DESCRIPTION | ||||
The | The | ||||
.Fn scandir | .Fn scandir | ||||
function | function | ||||
reads the directory | reads the directory | ||||
.Fa dirname | .Fa dirname | ||||
and builds an array of pointers to directory | and builds an array of pointers to directory | ||||
entries using | entries using | ||||
Show All 25 Lines | |||||
The | The | ||||
.Fn alphasort | .Fn alphasort | ||||
function | function | ||||
is a routine which can be used for the | is a routine which can be used for the | ||||
.Fa compar | .Fa compar | ||||
argument to sort the array alphabetically using | argument to sort the array alphabetically using | ||||
.Xr strcoll 3 . | .Xr strcoll 3 . | ||||
.Pp | .Pp | ||||
The | |||||
.Fn versionsort | |||||
function | |||||
is a routine which can be used for the | |||||
.Fa compar | |||||
argument to sort the array naturally using | |||||
.Xr strverscmp 3 . | |||||
.Pp | |||||
The memory allocated for the array can be deallocated with | The memory allocated for the array can be deallocated with | ||||
.Xr free 3 , | .Xr free 3 , | ||||
by freeing each pointer in the array and then the array itself. | by freeing each pointer in the array and then the array itself. | ||||
.Pp | .Pp | ||||
The | The | ||||
.Fn scandir_b | .Fn scandir_b | ||||
function behaves in the same way as | function behaves in the same way as | ||||
.Fn scandir , | .Fn scandir , | ||||
but takes blocks as arguments instead of function pointers and calls | but takes blocks as arguments instead of function pointers and calls | ||||
.Fn qsort_b | .Fn qsort_b | ||||
rather than | rather than | ||||
.Fn qsort . | .Fn qsort . | ||||
.Sh DIAGNOSTICS | .Sh DIAGNOSTICS | ||||
Returns \-1 if the directory cannot be opened for reading or if | Returns \-1 if the directory cannot be opened for reading or if | ||||
.Xr malloc 3 | .Xr malloc 3 | ||||
cannot allocate enough memory to hold all the data structures. | cannot allocate enough memory to hold all the data structures. | ||||
.Sh SEE ALSO | .Sh SEE ALSO | ||||
.Xr directory 3 , | .Xr directory 3 , | ||||
.Xr malloc 3 , | .Xr malloc 3 , | ||||
.Xr qsort 3 , | .Xr qsort 3 , | ||||
.Xr strcoll 3 , | .Xr strcoll 3 , | ||||
.Xr strverscmp 3 , | |||||
.Xr dir 5 | .Xr dir 5 | ||||
.Sh HISTORY | .Sh HISTORY | ||||
The | The | ||||
.Fn scandir | .Fn scandir | ||||
and | and | ||||
.Fn alphasort | .Fn alphasort | ||||
functions appeared in | functions appeared in | ||||
.Bx 4.2 . | .Bx 4.2 . | ||||
pauamma_gundo.com: I'd mention here that strverscmp came in 14.0 ( |
I'd mention here that strverscmp came in 14.0 (