As in the previous commit, 'de' is used as the iterator variable name.
_cleanup_closedir_ DIR *dir = NULL;
const char *dirpath;
- struct dirent *de;
int r;
assert(h);
struct dirent *readdir_ensure_type(DIR *d);
struct dirent *readdir_no_dot(DIR *dirp);
-#define FOREACH_DIRENT(de, d, on_error) \
- for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \
- if (!de) { \
- if (errno > 0) { \
- on_error; \
- } \
- break; \
- } else if (hidden_or_backup_file((de)->d_name)) \
- continue; \
- else
-
#define FOREACH_DIRENT_ALL(de, d, on_error) \
for (struct dirent *(de) = readdir_ensure_type(d);; (de) = readdir_ensure_type(d)) \
if (!de) { \
break; \
} else
+#define FOREACH_DIRENT(de, d, on_error) \
+ FOREACH_DIRENT_ALL(de, d, on_error) \
+ if (hidden_or_backup_file((de)->d_name)) \
+ continue; \
+ else
+
/* Maximum space one dirent structure might require at most */
#define DIRENT_SIZE_MAX CONST_MAX(sizeof(struct dirent), offsetof(struct dirent, d_name) + NAME_MAX + 1)
int close_all_fds(const int except[], size_t n_except) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
assert(n_except == 0 || except);
static int add_locales_from_libdir (Set *locales) {
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *entry;
int r;
dir = opendir("/usr/lib/locale");
if (!dir)
return errno == ENOENT ? 0 : -errno;
- FOREACH_DIRENT(entry, dir, return -errno) {
+ FOREACH_DIRENT(de, dir, return -errno) {
char *z;
- if (entry->d_type != DT_DIR)
+ if (de->d_type != DT_DIR)
continue;
- z = normalize_locale(entry->d_name);
+ z = normalize_locale(de->d_name);
if (!z)
return -ENOMEM;
return log_debug_errno(r, "Cannot open %s/usr/lib/extension-release.d/, ignoring: %m", root);
r = -ENOENT;
- struct dirent *de;
FOREACH_DIRENT(de, extension_release_dir, return -errno) {
int k;
int on_ac_power(void) {
bool found_offline = false, found_online = false;
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r;
d = opendir("/sys/class/power_supply");
r = read_one_line_file("/proc/device-tree/hypervisor/compatible", &hvtype);
if (r == -ENOENT) {
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
if (access("/proc/device-tree/ibm,partition-name", F_OK) == 0 &&
access("/proc/device-tree/hmc-managed?", F_OK) == 0 &&
return -errno;
}
- FOREACH_DIRENT(dent, dir, return -errno)
- if (strstr(dent->d_name, "fw-cfg")) {
- log_debug("Virtualization QEMU: \"fw-cfg\" present in /proc/device-tree/%s", dent->d_name);
+ FOREACH_DIRENT(de, dir, return -errno)
+ if (strstr(de->d_name, "fw-cfg")) {
+ log_debug("Virtualization QEMU: \"fw-cfg\" present in /proc/device-tree/%s", de->d_name);
return VIRTUALIZATION_QEMU;
}
static int enumerate_binaries(const char *esp_path, const char *path, const char *prefix) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
const char *p;
int c = 0, r;
}
static int install_binaries(const char *esp_path, bool force) {
- struct dirent *de;
_cleanup_closedir_ DIR *d = NULL;
int r = 0;
static int remove_boot_efi(const char *esp_path) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
const char *p;
int r, c = 0;
static int write_access2_rules(const char *srcdir) {
_cleanup_close_ int load2_fd = -1, change_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *entry;
int dfd = -1, r = 0;
load2_fd = open("/sys/fs/smackfs/load2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
static int write_cipso2_rules(const char *srcdir) {
_cleanup_close_ int cipso2_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *entry;
int dfd = -1, r = 0;
cipso2_fd = open("/sys/fs/smackfs/cipso2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
static int write_netlabel_rules(const char *srcdir) {
_cleanup_fclose_ FILE *dst = NULL;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *entry;
int dfd = -1, r = 0;
dst = fopen("/sys/fs/smackfs/netlabel", "we");
for (;;) {
_cleanup_(vacuum_candidate_hashmap_freep) Hashmap *h = NULL;
VacuumCandidate *worst = NULL;
- struct dirent *de;
uint64_t sum = 0;
rewinddir(d);
_cleanup_free_ char *buffer = NULL;
_cleanup_fclose_ FILE *stream = NULL;
const char *fddelim = "", *path;
- struct dirent *dent = NULL;
size_t size = 0;
int r;
if (!stream)
return -ENOMEM;
- FOREACH_DIRENT(dent, proc_fd_dir, return -errno) {
+ FOREACH_DIRENT(de, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
_cleanup_close_ int fd = -1;
- r = readlinkat_malloc(dirfd(proc_fd_dir), dent->d_name, &fdname);
+ r = readlinkat_malloc(dirfd(proc_fd_dir), de->d_name, &fdname);
if (r < 0)
return r;
- fprintf(stream, "%s%s:%s\n", fddelim, dent->d_name, fdname);
+ fprintf(stream, "%s%s:%s\n", fddelim, de->d_name, fdname);
fddelim = "\n";
/* Use the directory entry from /proc/[pid]/fd with /proc/[pid]/fdinfo */
- fd = openat(proc_fdinfo_fd, dent->d_name, O_NOFOLLOW|O_CLOEXEC|O_RDONLY);
+ fd = openat(proc_fdinfo_fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_RDONLY);
if (fd < 0)
continue;
static int manager_enumerate_records(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
assert(m);
int manager_enumerate_images(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
assert(m);
int server_restore_streams(Server *s, FDSet *fds) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
const char *path;
int r;
static int manager_enumerate_seats(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
assert(m);
static int manager_enumerate_linger_users(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
assert(m);
static int manager_enumerate_users(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r, k;
assert(m);
static int manager_enumerate_sessions(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0, k;
assert(m);
static int manager_enumerate_inhibitors(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
assert(m);
static int manager_enumerate_machines(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r;
assert(m);
static int find_loop_device(const char *backing_file, char **loop_dev) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
_cleanup_free_ char *l = NULL;
assert(backing_file);
STRV_FOREACH(i, paths.search_path) {
_cleanup_free_ char *resolved = NULL;
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
r = chase_symlinks_and_opendir(*i, where, 0, &resolved, &d);
if (r < 0) {
_cleanup_set_free_ Set *unit_files = NULL, *markers = NULL;
_cleanup_closedir_ DIR *d = NULL;
const char *where, *item;
- struct dirent *de;
int ret = 0;
int r;
_cleanup_set_free_ Set *unit_files = NULL;
_cleanup_closedir_ DIR *d = NULL;
const char *where;
- struct dirent *de;
int r;
assert(name_or_path);
static int list_files(PStoreList *list, const char *sourcepath) {
_cleanup_(closedirp) DIR *dirp = NULL;
- struct dirent *de;
int r;
dirp = opendir(sourcepath);
size_t *n_entries) {
_cleanup_(closedirp) DIR *d = NULL;
- struct dirent *de;
int r;
assert(root);
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
_cleanup_set_free_free_ Set *nodes = NULL;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
sd_device *d;
char *n;
int r;
* these devices are not known to the kernel at this moment */
dir = opendir("/run/udev/static_node-tags/uaccess");
if (dir) {
- FOREACH_DIRENT(dent, dir, return -errno) {
+ FOREACH_DIRENT(de, dir, return -errno) {
_cleanup_free_ char *unescaped_devname = NULL;
ssize_t l;
- l = cunescape(dent->d_name, UNESCAPE_RELAX, &unescaped_devname);
+ l = cunescape(de->d_name, UNESCAPE_RELAX, &unescaped_devname);
if (l < 0)
return l;
int efi_get_boot_options(uint16_t **options) {
_cleanup_closedir_ DIR *dir = NULL;
_cleanup_free_ uint16_t *list = NULL;
- struct dirent *de;
int count = 0;
assert(options);
int fdset_new_fill(FDSet **_s) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
FDSet *s;
size_t *n_changes) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
assert(remove_symlinks_to);
const char *config_path,
bool *same_name_link) {
- struct dirent *de;
int r = 0;
FOREACH_DIRENT(de, dir, return -errno) {
bool *same_name_link) {
_cleanup_closedir_ DIR *config_dir = NULL;
- struct dirent *de;
int r = 0;
assert(i);
STRV_FOREACH(i, paths.search_path) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
d = opendir(*i);
if (!d) {
STRV_FOREACH(dirname, paths.search_path) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
d = opendir(*dirname);
if (!d) {
static int numa_max_node(void) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r, max_node = 0;
d = opendir("/sys/devices/system/node");
_cleanup_(strv_freep) char **except = NULL, **only = NULL;
_cleanup_(closedirp) DIR *d = NULL;
- struct dirent *de;
const char *e;
int r, ret = 0;
STRV_FOREACH(path, sysvinit_path) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
d = opendir(*path);
if (!d) {
for (unsigned i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_free_ char *path = NULL;
- struct dirent *de;
path = path_join(*p, rcnd_table[i].path);
if (!path) {
TEST(proc) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r;
d = opendir("/proc");
TEST(get_process_cmdline) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
assert_se(d = opendir("/proc"));
static int process_password_files(void) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int r = 0;
d = opendir("/run/systemd/ask-password");
static int display_services(int argc, char *argv[], void *userdata) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_(closedirp) DIR *d = NULL;
- struct dirent *de;
int r;
d = opendir("/run/systemd/userdb/");
STRV_FOREACH(path, autostart_dirs) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
d = opendir(*path);
if (!d) {