HP-UX Reference (11i v3 07/02) - 3 Library Functions N-Z (vol 7)
s
scandir(3C) scandir(3C)
#include <dirent.h>
extern int scandir();
extern int alphasort();
main()
{
int num_entries, i;
struct dirent **namelist, **list;
if ((num_entries =
scandir("/tmp", &namelist, NULL, alphasort)) < 0) {
fprintf(stderr, "Unexpected error\n");
exit(1);
}
printf("Number of entries is %d\n", num_entries);
if (num_entries) {
printf("Entries are:");
for (i=0, list=namelist; i<num_entries; i++) {
printf(" %s", (*list)−>d_name);
free(*list);
list++;
}
}
free(namelist);
printf("\n");
exit(0);
}
WARNINGS
For 32-bit applications, the d_ino field of the
dirent struct returned by scandir() or alphasort()
may overflow for filesystems that use 64-bit values. In this case the most-significant bytes will be truncated
without generating an error and d_ino values may not be unique.
SEE ALSO
directory(3C), malloc(3C), qsort(3C), string(3C), dirent(5), thread_safety(5).
HP-UX 11i Version 3: February 2007 − 2 − Hewlett-Packard Company 369