summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-02-11 05:09:29 +0100
committerLennart Poettering <lennart@poettering.net>2013-02-11 05:09:29 +0100
commitf74e605fc06c1c23e968dc4c26045eb746791706 (patch)
treeecb00153e01723b375283c1444c69bebdba890f0 /src/shared/util.h
parent9b5d6bd909855543cba75a4469bff6f82845cf0d (diff)
util: introduce FOREACH_LINE for iterating through files
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 18494f14f2..d926b01919 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -567,3 +567,12 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
char *strip_tab_ansi(char **p, size_t *l);
int on_ac_power(void);
+
+#define FOREACH_LINE(f, line, on_error) \
+ for (char line[LINE_MAX]; !feof(f); ) \
+ if (!fgets(line, sizeof(line), f)) { \
+ if (ferror(f)) { \
+ on_error; \
+ } \
+ break; \
+ } else