--- scandir.3.orig 2009-11-07 14:51:38.000000000 -0800 +++ scandir.3 2009-11-07 14:51:40.000000000 -0800 @@ -28,15 +28,16 @@ .\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD: src/lib/libc/gen/scandir.3,v 1.9 2007/01/09 00:27:55 imp Exp $ .\" -.Dd June 4, 1993 +.Dd May 20, 2008 .Dt SCANDIR 3 .Os .Sh NAME .Nm scandir , +#ifdef UNIFDEF_BLOCKS +.Nm scandir_b , +#endif .Nm alphasort .Nd scan a directory -.Sh LIBRARY -.Lb libc .Sh SYNOPSIS .In sys/types.h .In dirent.h @@ -44,6 +45,10 @@ .Fn scandir "const char *dirname" "struct dirent ***namelist" "int \\*(lp*select\\*(rp\\*(lpstruct dirent *\\*(rp" "int \\*(lp*compar\\*(rp\\*(lpconst void *, const void *\\*(rp" .Ft int .Fn alphasort "const void *d1" "const void *d2" +#ifdef UNIFDEF_BLOCKS +.Ft int +.Fn scandir_b "const char *dirname" "struct dirent ***namelist" "int \\*(lp^select\\*(rp\\*(lpstruct dirent *\\*(rp" "int \\*(lp^compar\\*(rp\\*(lpconst void *, const void *\\*(rp" +#endif .Sh DESCRIPTION The .Fn scandir @@ -76,6 +81,13 @@ argument is a pointer to a user supplied .Xr qsort 3 to sort the completed array. If this pointer is null, the array is not sorted. +Note that from within the +.Fa compar +subroutine, the two arguments are of type +.Ft const struct dirent ** , +so that a double-dereference is needed to access the fields in the +.Ft dirent +structure. .Pp The .Fn alphasort @@ -87,6 +99,18 @@ argument to sort the array alphabeticall The memory allocated for the array can be deallocated with .Xr free 3 , by freeing each pointer in the array and then the array itself. +#ifdef UNIFDEF_BLOCKS +.Pp +The +.Fn scandir_b +function works the same way as the +.Fn scandir +function, except that +.Fa select +and +.Fa compar +are blocks instead of subroutines. +#endif .Sh DIAGNOSTICS Returns \-1 if the directory cannot be opened for reading or if .Xr malloc 3 @@ -103,3 +127,8 @@ and .Fn alphasort functions appeared in .Bx 4.2 . +#ifdef UNIFDEF_BLOCKS +The +.Fn scandir_b +function appeared in Mac OS X 10.6. +#endif