]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/kbd-util: simplify suffix stripping 18875/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Mar 2021 10:52:25 +0000 (11:52 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Mar 2021 10:52:25 +0000 (11:52 +0100)
It only came to me now that this can be prettified.

src/shared/kbd-util.c

index 430ae7c8815fceb5012fa5cc3cf95d76cbb73c29..92abaea65e1de5e370917a3afa35397d32ba074d 100644 (file)
@@ -22,7 +22,6 @@ static int nftw_cb(
                 struct FTW *ftwbuf) {
 
         _cleanup_free_ char *p = NULL;
-        char *e;
         int r;
 
         /* If keymap_name is non-null, return true if keymap keymap_name is found.
@@ -31,22 +30,18 @@ static int nftw_cb(
         if (tflag != FTW_F)
                 return 0;
 
-        if (!endswith(fpath, ".map") &&
-            !endswith(fpath, ".map.gz"))
+        fpath = basename(fpath);
+
+        const char *e = endswith(fpath, ".map") ?: endswith(fpath, ".map.gz");
+        if (!e)
                 return 0;
 
-        p = strdup(basename(fpath));
+        p = strndup(fpath, e - fpath);
         if (!p) {
                 errno = ENOMEM;
                 return -1;
         }
 
-        e = endswith(p, ".map");
-        if (!e)
-                e = endswith(p, ".map.gz");
-        if (e)
-                *e = 0;
-
         if (keymap_name)
                 return streq(p, keymap_name);