2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function scandir().
12 /*****************************************************************************
21 struct dirent
***namelist
,
22 int (*select
)(const struct dirent
*),
23 int (*compar
)(const struct dirent
**, const struct dirent
**)
30 dir - Directory to be scanned
31 namelist - Array with the found entries.
32 select - Filter function which must return non-zero if entry shall be
33 added. If NULL all entries will be added.
34 compar - Function which will be used by qsort() for sorting of the
35 entries. The function alphasort() can be used for sorting
36 in alphabetical oder. If NULL sorting order isn't specified.
52 ******************************************************************************/
58 struct dirent
**darr
= NULL
;
59 struct dirent
**newdarr
;
66 if ((dirp
= opendir(dir
)) == NULL
)
73 if ((dp
= readdir(dirp
)) != NULL
)
79 selected
= select(dp
);
82 if ((select
== NULL
) || selected
)
84 if ((darr
== NULL
) || cnt
>= arrcnt
)
87 newdarr
= realloc(darr
, arrcnt
* sizeof(*darr
));
94 newdp
= malloc(sizeof(*newdp
));
99 memcpy(newdp
, dp
, sizeof(*newdp
));
104 } while (dp
!= NULL
);
111 qsort (darr
, cnt
, sizeof (*darr
), (int (*) (const void *, const void *)) compar
);