+ return 0;
+}
+
+int unit_file_get_default(
+ UnitFileScope scope,
+ const char *root_dir,
+ char **name) {
+
+ _cleanup_lookup_paths_free_ LookupPaths paths = {};
+ char **p;
+ int r;
+
+ assert(scope >= 0);
+ assert(scope < _UNIT_FILE_SCOPE_MAX);
+ assert(name);
+
+ r = lookup_paths_init_from_scope(&paths, scope);
+ if (r < 0)
+ return r;
+
+ STRV_FOREACH(p, paths.unit_path) {
+ _cleanup_free_ char *path = NULL, *tmp = NULL;
+ char *n;
+
+ if (isempty(root_dir))
+ path = strappend(*p, "/" SPECIAL_DEFAULT_TARGET);
+ else
+ path = strjoin(root_dir, "/", *p, "/" SPECIAL_DEFAULT_TARGET, NULL);
+
+ if (!path)
+ return -ENOMEM;
+
+ r = readlink_malloc(path, &tmp);
+ if (r == -ENOENT)
+ continue;
+ else if (r == -EINVAL)
+ /* not a symlink */
+ n = strdup(SPECIAL_DEFAULT_TARGET);
+ else if (r < 0)
+ return r;
+ else
+ n = strdup(basename(tmp));
+
+ if (!n)
+ return -ENOMEM;
+
+ *name = n;
+ return 0;
+ }
+
+ return -ENOENT;