summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-11-19 02:50:21 +0100
committerLennart Poettering <lennart@poettering.net>2009-11-19 02:50:21 +0100
commita41e8209be729cd8de34d715135fe84920e8016c (patch)
tree10c0a3e6805a6475c7fb545b0dbc2366097bd778 /util.c
parented5bcfbe3c3b68e59242c03649eea03a9707d318 (diff)
util: add split_spaces() call
Diffstat (limited to 'util.c')
-rw-r--r--util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/util.c b/util.c
index bcb608480..4bec220f7 100644
--- a/util.c
+++ b/util.c
@@ -145,3 +145,22 @@ int safe_atoi(const char *s, int *ret_i) {
*ret_i = (unsigned) l;
return 0;
}
+
+/* What is interpreted as whitespace? */
+#define WHITESPACE " \t\n"
+
+/* Split a string into words. */
+char *split_spaces(const char *c, size_t *l, char **state) {
+ char *current;
+
+ current = *state ? *state : (char*) c;
+
+ if (!*current || *c == 0)
+ return NULL;
+
+ current += strspn(current, WHITESPACE);
+ *l = strcspn(current, WHITESPACE);
+ *state = current+*l;
+
+ return (char*) current;
+}