POSIX functions scandir() and alphasort() implemented.
[AROS.git] / test / clib / scandir.c
blob9f7fb6c7c70563782196744509d0e75f7a6ca1ba
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dirent.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 int filter(const struct dirent *de)
13 return !strcmp(de->d_name, "T");
16 void testscandir(const char *dir,
17 int (*select)(const struct dirent *),
18 int (*compar)(const struct dirent **, const struct dirent **))
20 int i;
21 struct dirent **namelist;
23 printf("\nscandir dir %s filter %p sort %p\n", dir, select, compar);
25 int res = scandir(dir, &namelist, select, compar);
26 printf("result %d\n", res);
27 if (res < 0)
29 perror("scandir");
31 else
33 for (i=0 ; i < res ; i++)
35 printf("%d %s\n", i, namelist[i]->d_name);
36 free(namelist[i]);
38 free(namelist);
42 int main(void)
44 testscandir("ram:", NULL, NULL);
45 testscandir("ram:", NULL, alphasort);
46 testscandir("ram:", filter, NULL);
47 return 0;