xkbcomp: simplify the include path handling
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 27 Jul 2020 01:55:32 +0000 (11:55 +1000)
committerRan Benita <ran@unusedvar.com>
Sun, 30 Aug 2020 18:49:41 +0000 (21:49 +0300)
Streamline the code a bit - instead of handling all the if (!file) conditions
handle the case of where we have a file and jump to the end.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/xkbcomp/include.c

index ac2279f0d20b22af4fc34714dde8312d4962e915..88feab36a2d70ea7309e36ea00d7f0519bca116a 100644 (file)
@@ -241,28 +241,21 @@ FindFileInXkbPath(struct xkb_context *ctx, const char *name,
         }
 
         file = fopen(buf, "rb");
-        if (!file) {
-            free(buf);
-            buf = NULL;
-        } else {
-            break;
+        if (file) {
+            if (pathRtrn) {
+                *pathRtrn = buf;
+                buf = NULL;
+            }
+            goto out;
         }
     }
 
-    if (!file) {
-        log_err(ctx, "Couldn't find file \"%s/%s\" in include paths\n",
-                typeDir, name);
+    log_err(ctx, "Couldn't find file \"%s/%s\" in include paths\n",
+            typeDir, name);
+    LogIncludePaths(ctx);
 
-        LogIncludePaths(ctx);
-
-        free(buf);
-        return NULL;
-    }
-
-    if (pathRtrn)
-        *pathRtrn = buf;
-    else
-        free(buf);
+out:
+    free(buf);
     return file;
 }