DIR *d;
int err;
struct stat st;
+ struct dirent *dent;
if (stat(path, &st) != 0) {
err = -errno;
return -EINVAL;
}
- for (;;) {
- struct dirent ent, *entp;
-
- err = readdir_r(d, &ent, &entp);
- if (err != 0) {
- ERR(ctx, "reading entry %s\n", strerror(-err));
- goto fail_read;
- }
-
- if (entp == NULL)
- break;
-
- if (conf_files_filter_out(ctx, d, path, entp->d_name))
+ for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
+ if (conf_files_filter_out(ctx, d, path, dent->d_name))
continue;
- conf_files_insert_sorted(ctx, list, path, entp->d_name);
+ conf_files_insert_sorted(ctx, list, path, dent->d_name);
}
closedir(d);
return 0;
-
-fail_read:
- closedir(d);
- return err;
}
int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
{
char dname[PATH_MAX];
struct kmod_list *list = NULL;
+ struct dirent *dent;
DIR *d;
if (mod == NULL || mod->ctx == NULL)
return NULL;
}
- for (;;) {
- struct dirent de, *entp;
+ for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
struct kmod_module *holder;
struct kmod_list *l;
int err;
- err = readdir_r(d, &de, &entp);
- if (err != 0) {
- ERR(mod->ctx, "could not iterate for module '%s': %s\n",
- mod->name, strerror(-err));
- goto fail;
- }
-
- if (entp == NULL)
- break;
-
- if (de.d_name[0] == '.') {
- if (de.d_name[1] == '\0' ||
- (de.d_name[1] == '.' && de.d_name[2] == '\0'))
+ if (dent->d_name[0] == '.') {
+ if (dent->d_name[1] == '\0' ||
+ (dent->d_name[1] == '.' && dent->d_name[2] == '\0'))
continue;
}
- err = kmod_module_new_from_name(mod->ctx, de.d_name, &holder);
+ err = kmod_module_new_from_name(mod->ctx, dent->d_name,
+ &holder);
if (err < 0) {
ERR(mod->ctx, "could not create module for '%s': %s\n",
- de.d_name, strerror(-err));
+ dent->d_name, strerror(-err));
goto fail;
}
{
char dname[PATH_MAX];
struct kmod_list *list = NULL;
+ struct dirent *dent;
DIR *d;
int dfd;
dfd = dirfd(d);
- for (;;) {
- struct dirent de, *entp;
+ for (dent = readdir(d); dent; dent = readdir(d)) {
struct kmod_module_section *section;
struct kmod_list *l;
unsigned long address;
size_t namesz;
int fd, err;
- err = readdir_r(d, &de, &entp);
- if (err != 0) {
- ERR(mod->ctx, "could not iterate for module '%s': %s\n",
- mod->name, strerror(-err));
- goto fail;
- }
-
- if (de.d_name[0] == '.') {
- if (de.d_name[1] == '\0' ||
- (de.d_name[1] == '.' && de.d_name[2] == '\0'))
+ if (dent->d_name[0] == '.') {
+ if (dent->d_name[1] == '\0' ||
+ (dent->d_name[1] == '.' && dent->d_name[2] == '\0'))
continue;
}
- fd = openat(dfd, de.d_name, O_RDONLY|O_CLOEXEC);
+ fd = openat(dfd, dent->d_name, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
ERR(mod->ctx, "could not open '%s/%s': %m\n",
- dname, de.d_name);
+ dname, dent->d_name);
goto fail;
}
close(fd);
if (err < 0) {
ERR(mod->ctx, "could not read long from '%s/%s': %m\n",
- dname, de.d_name);
+ dname, dent->d_name);
goto fail;
}
- namesz = strlen(de.d_name) + 1;
+ namesz = strlen(dent->d_name) + 1;
section = malloc(sizeof(*section) + namesz);
if (section == NULL) {
}
section->address = address;
- memcpy(section->name, de.d_name, namesz);
+ memcpy(section->name, dent->d_name, namesz);
l = kmod_list_append(list, section);
if (l != NULL) {
static int cfg_files_list(struct cfg_file ***p_files, size_t *p_n_files,
const char *path)
{
+ struct dirent *dent;
DIR *d;
int err = 0;
struct stat st;
return -EINVAL;
}
- for (;;) {
- struct dirent ent, *entp;
-
- err = readdir_r(d, &ent, &entp);
- if (err != 0) {
- ERR("reading entry %s\n", strerror(-err));
- break;
- }
- if (entp == NULL)
- break;
- if (cfg_files_filter_out(d, path, entp->d_name))
+ for (dent = readdir(d); dent != NULL; dent = readdir(d)) {
+ if (cfg_files_filter_out(d, path, dent->d_name))
continue;
- cfg_files_insert_sorted(p_files, p_n_files, path, entp->d_name);
+ cfg_files_insert_sorted(p_files, p_n_files, path, dent->d_name);
}
closedir(d);