chiark / gitweb /
Allow for the use of @ in remote host calls
[elogind.git] / src / shared / util.c
index 673e0da6b69f38112708581ff81abe65a1675c1b..d0bbf78bf371cc2340bbb7952193df5bdda12c20 100644 (file)
@@ -850,18 +850,18 @@ int readlink_malloc(const char *p, char **r) {
 }
 
 int readlink_and_make_absolute(const char *p, char **r) {
-        char *target, *k;
+        _cleanup_free_ char *target = NULL;
+        char *k;
         int j;
 
         assert(p);
         assert(r);
 
-        if ((j = readlink_malloc(p, &target)) < 0)
+        j = readlink_malloc(p, &target);
+        if (j < 0)
                 return j;
 
         k = file_in_same_dir(p, target);
-        free(target);
-
         if (!k)
                 return -ENOMEM;
 
@@ -5847,3 +5847,17 @@ bool id128_is_valid(const char *s) {
 
         return true;
 }
+
+void parse_user_at_host(char *arg, char **user, char **host) {
+        assert(arg);
+        assert(user);
+        assert(host);
+
+        *host = strchr(arg, '@');
+        if (*host == NULL)
+                *host = arg;
+        else {
+                *host[0]++ = '\0';
+                *user = arg;
+        }
+}