summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c31
1 files changed, 31 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;
+}