summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-18 20:22:29 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-18 20:22:29 +0200
commitd4ac85c6f6d8547f8b835009ae431438de72df28 (patch)
treec18be6d1c1af7efaa740beeac594be8cd61d62e9 /src/shared
parent2f5df74a5ec135ab2baebf26af6f088e5b4b8205 (diff)
util: add split_pair() for splitting foo=bar strings
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c31
-rw-r--r--src/shared/util.h2
2 files changed, 33 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 5b602ea46d..c8ed53c8b6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5946,3 +5946,34 @@ void parse_user_at_host(char *arg, char **user, char **host) {
*user = arg;
}
}
+
+int split_pair(const char *s, const char *sep, char **l, char **r) {
+ char *x, *a, *b;
+
+ assert(s);
+ assert(sep);
+ assert(l);
+ assert(r);
+
+ if (isempty(sep))
+ return -EINVAL;
+
+ x = strstr(s, sep);
+ if (!x)
+ return -EINVAL;
+
+ a = strndup(s, x - s);
+ if (!a)
+ return -ENOMEM;
+
+ b = strdup(x + strlen(sep));
+ if (!b) {
+ free(a);
+ return -ENOMEM;
+ }
+
+ *l = a;
+ *r = b;
+
+ return 0;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index fac08ca43c..ac999c624c 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -735,3 +735,5 @@ static inline void _reset_locale_(struct _locale_struct_ *s) {
bool id128_is_valid(const char *s) _pure_;
void parse_user_at_host(char *arg, char **user, char **host);
+
+int split_pair(const char *s, const char *sep, char **l, char **r);