Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

scandir(3c) [opensolaris man page]

scandir(3C)						   Standard C Library Functions 					       scandir(3C)

NAME
scandir, alphasort - scan a directory SYNOPSIS
#include <sys/types.h> #include <dirent.h> int scandir(const char *dirname, struct dirent *(*namelist[]), int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, const struct dirent **)); int alphasort(const struct dirent **d1, const struct dirent **d2); DESCRIPTION
The scandir() function reads the directory dirname using readdir(3C) and builds an array of pointers to directory entries using malloc(3C). The namelist argument is a pointer to an array of structure pointers. The 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 NULL, then all the directory entries are included. The dcomp argument is a pointer to a routine that is passed to qsort(3C), which sorts the completed array. If this pointer is NULL, the array is not sorted. The alphasort() function can be used as the dcomp() function parameter for the scandir() function to sort the directory entries into alpha- betical order, as if by the strcoll(3C) function. Its arguments are the two directory entries to compare. RETURN VALUES
The scandir() function returns the number of entries in the array and a pointer to the array through the namelist argument. When an error is encountered, scandir() returns -1 and errno is set to indicate the error. The alphasort() function returns an integer greater than, equal to, or less than 0 if the directory entry name pointed to by d1 is greater than, equal to, or less than the directory entry name pointed to by d2 when both are interpreted as appropriate to the current locale. There is no return value reserved to indicate an error. ERRORS
The scandir() function will fail if: EOVERFLOW The number of directory entries exceeds the number that can be represented by an int. USAGE
The scandir() and alphasort() functions have transitional interfaces for 64-bit file offsets. See lf64(5). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |See below. | +-----------------------------+-----------------------------+ The scandir() function is Unsafe. The alphasort() function is Safe. SEE ALSO
malloc(3C), qsort(3C), readdir(3C), strcoll(3C), attributes(5), lf64(5) SunOS 5.11 4 May 2004 scandir(3C)

Check Out this Related Man Page

scandir(3UCB)					     SunOS/BSD Compatibility Library Functions					     scandir(3UCB)

NAME
scandir, alphasort - scan a directory SYNOPSIS
/usr/ucb/cc [ flag... ] file... #include <sys/types.h> #include <sys/dir.h> int scandir(dirname, namelist, select, dcomp) char *dirname; struct direct *(*namelist[]); int (*select(), (*dcomp)(); int alphasort(d1, d2) struct direct **d1, **d2; DESCRIPTION
The scandir() function reads the directory dirname and builds an array of pointers to directory entries using malloc(3C). The second param- eter 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 NULL, then all the directory entries will be included. The last argument is a pointer to a routine which is passed to qsort(3C), which sorts the com- pleted array. If this pointer is NULL, the array is not sorted. The alphasort() function sorts the array alphabetically. RETURN VALUES
The scandir() function returns the number of entries in the array and a pointer to the array through the parameter namelist. The scandir() function returns -1 if the directory cannot be opened for reading or if malloc(3C) cannot allocate enough memory to hold all the data structures. The alphasort() function returns an integer greater than, equal to, or less than 0 if the directory entry name pointed to by d1 is greater than, equal to, or less than the directory entry name pointed to by d2. USAGE
The scandir() and alphasort() functions have transitional interfaces for 64-bit file offsets. See lf64(5). SEE ALSO
cc(1B), getdents(2), malloc(3C), qsort(3C), readdir(3UCB), readdir(3C), lf64(5) NOTES
Use of these functions should be restricted to applications written on BSD platforms. Use of these functions with any of the system libraries or in multithreaded applications is unsupported. SunOS 5.11 30 Oct 2007 scandir(3UCB)
Man Page