From 9db11a99beaf25f6eb948348202a4c783e1d31a6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Feb 2013 22:02:40 +0100 Subject: efi: efi_get_boot_options() should already sort the entries, the random order in the efivars fs is probably not useful This also introduces a new FOREACH_DIRENT macro and makes use of it. --- src/shared/util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/shared/util.h') diff --git a/src/shared/util.h b/src/shared/util.h index 3ad90ddce4..fcb0d9af17 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -573,11 +573,22 @@ int on_ac_power(void); int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f); int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f); -#define FOREACH_LINE(f, line, on_error) \ - for (char line[LINE_MAX]; !feof(f); ) \ +#define FOREACH_LINE(line, f, on_error) \ + for (;;) \ if (!fgets(line, sizeof(line), f)) { \ if (ferror(f)) { \ on_error; \ } \ break; \ } else + +#define FOREACH_DIRENT(de, d, on_error) \ + for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ + if (!de) { \ + if (errno != 0) { \ + on_error; \ + } \ + break; \ + } else if (ignore_file((de)->d_name)) \ + continue; \ + else -- cgit v1.2.3-54-g00ecf