*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Tru64 Unix man pages -> alphasort (3)              
Title
Content
Arch
Section
 

scandir(3)

Contents


NAME    [Toc]    [Back]

       scandir, alphasort - Scan or sorts directory contents

SYNOPSIS    [Toc]    [Back]

       #include <sys/types.h> #include <sys/dir.h>

       int scandir(
               char *dir_name,
               struct dirent *(*name_list []),
               int (*compare)(struct dirent **dir1, struct dirent
       **dir2) ); int alphasort(
               struct dirent **dir1,
               struct dirent **dir2 );

LIBRARY    [Toc]    [Back]

       Standard C Library (libc)

PARAMETERS    [Toc]    [Back]

       Points to the directory name.   Points  to  the  array  of
       pointers  to directory entries.  Points to a user-supplied
       function that is  called  by  the  scandir()  function  to
       select which entries to include in the array.  Points to a
       user-supplied function that  sorts  the  completed  array.
       Points  to  a dirent structure.  Points to a dirent structure.

DESCRIPTION    [Toc]    [Back]

       The scandir() function reads the directory pointed  to  by
       the dir_name parameter. It then uses the malloc() function
       to create an array of pointers to directory  entries.  The
       scandir()  function  returns  the number of entries in the
       array and, through the name_list parameter, a  pointer  to
       the array.

       The  select  parameter  points to a user-supplied function
       that the scandir() function calls to select which  entries
       to include in the array. The selection routine is passed a
       pointer to a directory entry and returns a  nonzero  value
       for  a  directory  entry that is included in the array. If
       the select  parameter  is  a  null  value,  all  directory
       entries are included.

       The  compare  parameter points to a user-supplied function
       that is passed to the qsort() function to  sort  the  completed
  array.  If  the compare parameter is a null value,
       the array is not sorted.

       The memory allocated to the array can  be  deallocated  by
       freeing  each  pointer in the array, and the array itself,
       with the free() function.

       The alphasort() function alphabetically compares  the  two
       dirent  structures pointed to by the dir1 and dir2 parameters.
 This function can be passed as the compare parameter
       to  either the scandir() function or the qsort() function.
       A user-supplied subroutine may also be used.






RETURN VALUES    [Toc]    [Back]

       The scandir() function returns -1 if the directory  cannot
       be  opened  for reading or if the malloc() function cannot
       allocate enough memory to hold all the data structures. If
       successful,  the  scandir() function returns the number of
       entries found.

       The alphasort() function  returns  the  following  values:
       Less than 0 (zero): The dirent structure pointed to by the
       dir1 parameter is lexically less than the dirent structure
       pointed  to  by  the dir2 parameter.  0 (zero): The dirent
       structures pointed to by the dir1 parameter and  the  dir2
       parameter  are  equal.   Greater than 0 (zero): The dirent
       structure pointed to by the dir1  parameter  is  lexically
       greater  than  the  direntstructure pointed to by the dir2
       parameter.

SEE ALSO    [Toc]    [Back]

      
      
       Functions: malloc(3), opendir(3), qsort(3)



                                                       scandir(3)
[ Back ]
 Similar pages
Name OS Title
alphasort NetBSD scan a directory
alphasort OpenBSD scan a directory
alphasort FreeBSD scan a directory
scandir FreeBSD scan a directory
scandir OpenBSD scan a directory
scandir NetBSD scan a directory
scandir IRIX scan a directory
scandir Linux scan a directory for matching entries
nisls HP-UX list the contents of an NIS+ directory
VOP_READDIR FreeBSD read contents of a directory
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service