chiark / gitweb /
util: add api for iterating through components of a path string
[elogind.git] / util.c
diff --git a/util.c b/util.c
index bf74695854932a79f93d629c8f79a0664a144358..c5c8bd4edda6d68f1ef88607b9d09c559e42840a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -284,6 +284,22 @@ char *split_spaces(const char *c, size_t *l, char **state) {
         return (char*) current;
 }
 
+/* Split a path into filenames. */
+char *split_slash(const char *c, size_t *l, char **state) {
+        char *current;
+
+        current = *state ? *state : (char*) c;
+
+        if (!*current || *c == 0)
+                return NULL;
+
+        current += strspn(current, "/");
+        *l = strcspn(current, "/");
+        *state = current+*l;
+
+        return (char*) current;
+}
+
 /* Split a string into words, but consider strings enclosed in '' and
  * "" as words even if they include spaces. */
 char *split_quoted(const char *c, size_t *l, char **state) {