diff options
author | Reverend Homer <mk.43.ecko@gmail.com> | 2016-12-09 12:04:30 +0300 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-12-09 10:04:30 +0100 |
commit | 8fb3f0099787a5b48213c4e2aa42d8ff61b0c7f1 (patch) | |
tree | c9bf990e18daac08ec1e744d6be365a9e98d2532 /src/basic/util.c | |
parent | 9258a1cae3985ee590f1c698451bd7909aa38d2b (diff) |
tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)
Diffstat (limited to 'src/basic/util.c')
-rw-r--r-- | src/basic/util.c | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/src/basic/util.c b/src/basic/util.c index c1b5ca1ef7..8a630049d7 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -18,7 +18,6 @@ ***/ #include <alloca.h> -#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <sched.h> @@ -508,28 +507,17 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int on_ac_power(void) { bool found_offline = false, found_online = false; _cleanup_closedir_ DIR *d = NULL; + struct dirent *de; d = opendir("/sys/class/power_supply"); if (!d) return errno == ENOENT ? true : -errno; - for (;;) { - struct dirent *de; + FOREACH_DIRENT(de, d, return -errno) { _cleanup_close_ int fd = -1, device = -1; char contents[6]; ssize_t n; - errno = 0; - de = readdir(d); - if (!de && errno > 0) - return -errno; - - if (!de) - break; - - if (hidden_or_backup_file(de->d_name)) - continue; - device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY); if (device < 0) { if (errno == ENOENT || errno == ENOTDIR) |