// A smart pointer to the scandir dirent**. class ScandirResult { public:
ScandirResult() : names_(nullptr), size_(0), capacity_(0) {
}
~ScandirResult() { // We always call release(), so this can't happen. if (names_ != nullptr) __assert(__FILE__, __LINE__, "missing call to release()");
}
int scandirat(int parent_fd, constchar* dir_name, dirent*** name_list, int (*filter)(const dirent*), int (*comparator)(const dirent**, const dirent**)) {
DIR* dir = nullptr; if (parent_fd == AT_FDCWD) {
dir = opendir(dir_name);
} else { int dir_fd = openat(parent_fd, dir_name, O_CLOEXEC | O_DIRECTORY | O_RDONLY); if (dir_fd != -1) {
dir = fdopendir(dir_fd);
}
}
ScopedReaddir reader(dir); if (reader.IsBad()) { return -1;
}
ScandirResult names;
dirent* entry; while ((entry = reader.ReadEntry()) != nullptr) { // If we have a filter, skip names that don't match. if (filter != nullptr && !(*filter)(entry)) { continue;
}
names.Add(entry);
}
if (comparator != nullptr) {
names.Sort(comparator);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.