From: Zbigniew Jędrzejewski-Szmek Date: Thu, 4 Mar 2021 10:52:25 +0000 (+0100) Subject: shared/kbd-util: simplify suffix stripping X-Git-Tag: v248-rc3~50^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F18875%2Fhead;p=thirdparty%2Fsystemd.git shared/kbd-util: simplify suffix stripping It only came to me now that this can be prettified. --- diff --git a/src/shared/kbd-util.c b/src/shared/kbd-util.c index 430ae7c8815..92abaea65e1 100644 --- a/src/shared/kbd-util.c +++ b/src/shared/kbd-util.c @@ -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);