mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-14 20:37:06 +00:00
libc: add scandirat(3)
Reviewed by: emaste, imp, kevans, markj, Aymeric Wibo <obiwac@gmail.com> Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36301
This commit is contained in:
parent
cb6e97f4da
commit
9fb8e8eede
|
@ -131,6 +131,11 @@ int scandir_b(const char *, struct dirent ***,
|
|||
int (^)(const struct dirent **, const struct dirent **));
|
||||
#endif
|
||||
#endif
|
||||
#if __BSD_VISIBLE
|
||||
int scandirat(int, const char *, struct dirent ***,
|
||||
int (*)(const struct dirent *), int (*)(const struct dirent **,
|
||||
const struct dirent **));
|
||||
#endif
|
||||
#if __XSI_VISIBLE
|
||||
void seekdir(DIR *, long);
|
||||
long telldir(DIR *);
|
||||
|
|
|
@ -439,6 +439,7 @@ FBSD_1.7 {
|
|||
posix_spawn_file_actions_addchdir_np;
|
||||
posix_spawn_file_actions_addclosefrom_np;
|
||||
posix_spawn_file_actions_addfchdir_np;
|
||||
scandirat;
|
||||
sched_getaffinity;
|
||||
sched_setaffinity;
|
||||
sched_getcpu;
|
||||
|
|
|
@ -42,8 +42,10 @@ __FBSDID("$FreeBSD$");
|
|||
|
||||
#include "namespace.h"
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#ifdef I_AM_SCANDIR_B
|
||||
|
@ -159,6 +161,25 @@ scandir(const char *dirname, struct dirent ***namelist,
|
|||
}
|
||||
|
||||
#ifndef I_AM_SCANDIR_B
|
||||
int
|
||||
scandirat(int dirfd, const char *dirname, struct dirent ***namelist,
|
||||
int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
|
||||
const struct dirent **))
|
||||
{
|
||||
DIR *dirp;
|
||||
int fd;
|
||||
|
||||
fd = _openat(dirfd, dirname, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
||||
if (fd == -1)
|
||||
return (-1);
|
||||
dirp = fdopendir(fd);
|
||||
if (dirp == NULL) {
|
||||
_close(fd);
|
||||
return (-1);
|
||||
}
|
||||
return (scandir_dirp(dirp, namelist, select, dcomp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Alphabetic order comparison routine for those who want it.
|
||||
* POSIX 2008 requires that alphasort() uses strcoll().
|
||||
|
|
Loading…
Reference in a new issue