]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
install: simplify skip_root() a bit
authorLennart Poettering <lennart@poettering.net>
Fri, 8 Apr 2016 15:58:53 +0000 (17:58 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:32 +0000 (13:43 +0200)
Exit early, so that we can get rid of the large if block.

src/shared/install.c

index 3d48f612f3c639b1eff4e650971adf7609d3b343..3289b51f41de132197e8cdfc86e2c09367437609 100644 (file)
@@ -85,25 +85,27 @@ static int in_search_path(const LookupPaths *p, const char *path) {
 }
 
 static const char* skip_root(const LookupPaths *p, const char *path) {
-        if (p->root_dir) {
-                char *e;
+        char *e;
 
-                e = path_startswith(path, p->root_dir);
-                if (!e)
-                        return NULL;
+        assert(p);
+        assert(path);
 
-                /* Make sure the returned path starts with a slash */
-                if (e[0] != '/') {
-                        if (e == path || e[-1] != '/')
-                                return NULL;
+        if (!p->root_dir)
+                return path;
 
-                        e--;
-                }
+        e = path_startswith(path, p->root_dir);
+        if (!e)
+                return NULL;
+
+        /* Make sure the returned path starts with a slash */
+        if (e[0] != '/') {
+                if (e == path || e[-1] != '/')
+                        return NULL;
 
-                return e;
+                e--;
         }
 
-        return path;
+        return e;
 }
 
 static int path_is_generator(const LookupPaths *p, const char *path) {