summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorSimon Peeters <peeters.simon@gmail.com>2014-01-04 02:35:25 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-05 09:16:15 -0500
commitbf85c24daaf63f72562bbe4c627ca8b963dfb964 (patch)
treeaa40aeb48ed769164007c8dc52329870dd05a548 /src/shared/util.h
parente10e429f2dcbb586215e65f62847f40c7d8b5956 (diff)
shared: util.c: unify split and split_quoted
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 8645654267..ebc765da35 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -198,17 +198,22 @@ static inline int safe_atoi64(const char *s, int64_t *ret_i) {
return safe_atolli(s, (long long int*) ret_i);
}
-char *split(const char *c, size_t *l, const char *separator, char **state);
-char *split_quoted(const char *c, size_t *l, char **state);
+char *split(const char *c, size_t *l, const char *separator, bool quoted, char **state);
#define FOREACH_WORD(word, length, s, state) \
- for ((state) = NULL, (word) = split((s), &(length), WHITESPACE, &(state)); (word); (word) = split((s), &(length), WHITESPACE, &(state)))
+ _FOREACH_WORD(word, length, s, WHITESPACE, false, state)
#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state) \
- for ((state) = NULL, (word) = split((s), &(length), (separator), &(state)); (word); (word) = split((s), &(length), (separator), &(state)))
+ _FOREACH_WORD(word, length, s, separator, false, state)
#define FOREACH_WORD_QUOTED(word, length, s, state) \
- for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state)))
+ _FOREACH_WORD(word, length, s, WHITESPACE, true, state)
+
+#define FOREACH_WORD_SEPARATOR_QUOTED(word, length, s, separator, state) \
+ _FOREACH_WORD(word, length, s, separator, true, state)
+
+#define _FOREACH_WORD(word, length, s, separator, quoted, state) \
+ for ((state) = NULL, (word) = split((s), &(length), (separator), (quoted), &(state)); (word); (word) = split((s), &(length), (separator), (quoted), &(state)))
pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
int get_starttime_of_pid(pid_t pid, unsigned long long *st);