1scandir(3C)              Standard C Library Functions              scandir(3C)
2
3
4

NAME

6       scandir, alphasort - scan a directory
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <dirent.h>
11
12       int scandir(const char *dirname, struct dirent *(*namelist[]),
13            int (*select)(const struct dirent *),
14            int (*dcomp)(const struct dirent  **,
15            const struct dirent **));
16
17
18       int alphasort(const struct dirent **d1,
19            const struct dirent **d2);
20
21

DESCRIPTION

23       The  scandir()  function  reads the directory dirname using readdir(3C)
24       and builds an array of pointers to directory entries using  malloc(3C).
25       The  namelist  argument is a pointer to an array of structure pointers.
26       The select argument is a pointer to a routine that  is  called  with  a
27       pointer to a directory entry and returns a non-zero value if the direc‐
28       tory entry is included in the array. If this pointer is NULL, then  all
29       the  directory entries are included. The dcomp argument is a pointer to
30       a routine that is passed to qsort(3C), which sorts the completed array.
31       If this pointer is NULL, the array is not sorted.
32
33
34       The  alphasort() function can be used as the dcomp() function parameter
35       for the scandir() function to sort the directory entries into alphabet‐
36       ical  order,  as  if by the strcoll(3C) function. Its arguments are the
37       two directory entries to compare.
38

RETURN VALUES

40       The scandir() function returns the number of entries in the array and a
41       pointer  to  the  array through the namelist argument. When an error is
42       encountered, scandir() returns -1 and errno  is  set  to  indicate  the
43       error.
44
45
46       The  alphasort() function returns an integer greater than, equal to, or
47       less than 0 if the directory entry name pointed to  by  d1  is  greater
48       than,  equal to, or less than the directory entry name pointed to by d2
49       when both are interpreted as appropriate to the current  locale.  There
50       is no return value reserved to indicate an error.
51

ERRORS

53       The scandir() function will fail if:
54
55       EOVERFLOW    The  number  of  directory entries exceeds the number that
56                    can be represented by an int.
57
58

USAGE

60       The scandir() and alphasort() functions  have  transitional  interfaces
61       for 64-bit file offsets. See lf64(5).
62

ATTRIBUTES

64       See attributes(5) for descriptions of the following attributes:
65
66
67
68
69       ┌─────────────────────────────┬─────────────────────────────┐
70       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
71       ├─────────────────────────────┼─────────────────────────────┤
72       │Interface Stability          │Stable                       │
73       ├─────────────────────────────┼─────────────────────────────┤
74       │MT-Level                     │See below.                   │
75       └─────────────────────────────┴─────────────────────────────┘
76
77
78       The scandir() function is Unsafe. The alphasort() function is Safe.
79

SEE ALSO

81       malloc(3C), qsort(3C), readdir(3C), strcoll(3C), attributes(5), lf64(5)
82
83
84
85SunOS 5.11                        4 May 2004                       scandir(3C)
Impressum