diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-04 11:52:25 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-04 11:52:25 +0100 |
commit | 73d0806abb3217dd4f3c0f9859bef4813cb96c99 (patch) | |
tree | 54e7d848f38a55f01be42ab2ff29a9393db2db6d /src/shared/kbd-util.c | |
parent | 9ef70c06c663a05f7646d690e00e4b4a73af8c61 (diff) | |
download | systemd-73d0806abb3217dd4f3c0f9859bef4813cb96c99.tar.gz |
shared/kbd-util: simplify suffix stripping
It only came to me now that this can be prettified.
Diffstat (limited to 'src/shared/kbd-util.c')
-rw-r--r-- | src/shared/kbd-util.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/shared/kbd-util.c b/src/shared/kbd-util.c index 430ae7c881..92abaea65e 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); |