scandir(3) Library Functions Manual scandir(3) scandir, scandirat, alphasort, versionsort - (libc -lc) #include int scandir(const char *restrict dirp, struct dirent ***restrict namelist, typeof(int (const struct dirent *)) *filter, typeof(int (const struct dirent **, const struct dirent **)) *compar); int alphasort(const struct dirent **a, const struct dirent **b); int versionsort(const struct dirent **a, const struct dirent **b); #include /* AT_* */ #include int scandirat(int dirfd, const char *restrict dirp, struct dirent ***restrict namelist, typeof(int (const struct dirent *)) *filter, typeof(int (const struct dirent **, const struct dirent **)) *compar); glibc ( feature_test_macros(7)): scandir(), alphasort(): /* glibc 2.10: */ _POSIX_C_SOURCE >= 200809L || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE versionsort(): _GNU_SOURCE scandirat(): _GNU_SOURCE scandir() dirp filter() . filter() malloc(3) qsort(3) compar() namelist malloc(3). filter NULL . alphasort() versionsort() compar(). strcoll(3) strverscmp(3) (*a)->d_name (*b)->d_name. scandirat() scandirat() scandir() . dirp dirfd ( scandir() ). dirp dirfd AT_FDCWD dirp ( scandir()). dirp dirfd. openat(2) scandirat(). scandir() . -1 errno . alphasort() versionsort() . EBADF (scandirat()) dirp dirfd AT_FDCWD . ENOENT dirp . ENOMEM . ENOTDIR dirp . ENOTDIR (scandirat()) dirp dirfd . attributes(7). +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ | | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ |scandir() | | MT-Safe | |scandirat() | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ |alphasort() | | (locale) (MT-Safe) | |versionsort() | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ alphasort() scandir() POSIX.1-2008. versionsort() scandirat() GNU. alphasort() scandir() 4.3BSD POSIX.1-2008. versionsort() glibc 2.1. scandirat() glibc 2.15. glibc 2.1 alphasort() strcoll(3) strcmp(3). glibc 2.10 alphasort() versionsort() const void *. alphasort() POSIX.1-2008 const struct dirent ** glibc 2.10 alphasort() ( versionsort() ) . . #define _DEFAULT_SOURCE #include #include #include int main(void) { struct dirent **namelist; int n; n = scandir(".", &namelist, NULL, alphasort); if (n == -1) { perror("scandir"); exit(EXIT_FAILURE); } while (n--) { printf("%s\n", namelist[n]->d_name); free(namelist[n]); } free(namelist); exit(EXIT_SUCCESS); } closedir(3) fnmatch(3) opendir(3) readdir(3) rewinddir(3) seekdir(3) strcmp(3) strcoll(3) strverscmp(3) telldir(3) 3 . . : . 6.18 8 2026 scandir(3)