]>
git.proxmox.com Git - systemd.git/blob - src/basic/kbd-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "nulstr-util.h"
10 #include "string-util.h"
14 static thread_local Set
*keymaps
= NULL
;
18 const struct stat
*sb
,
22 _cleanup_free_
char *p
= NULL
;
29 if (!endswith(fpath
, ".map") &&
30 !endswith(fpath
, ".map.gz"))
33 p
= strdup(basename(fpath
));
37 e
= endswith(p
, ".map");
41 e
= endswith(p
, ".map.gz");
45 if (!keymap_is_valid(p
))
48 r
= set_consume(keymaps
, TAKE_PTR(p
));
49 if (r
< 0 && r
!= -EEXIST
)
55 int get_keymaps(char ***ret
) {
56 _cleanup_strv_free_
char **l
= NULL
;
60 keymaps
= set_new(&string_hash_ops
);
64 NULSTR_FOREACH(dir
, KBD_KEYMAP_DIRS
) {
65 r
= nftw(dir
, nftw_cb
, 20, FTW_PHYS
|FTW_ACTIONRETVAL
);
68 log_debug("Directory not found %s", dir
);
70 log_debug_errno(r
, "Can't add keymap: %m");
73 l
= set_get_strv(keymaps
);
75 set_free_free(keymaps
);
91 bool keymap_is_valid(const char *name
) {
96 if (strlen(name
) >= 128)
99 if (!utf8_is_valid(name
))
102 if (!filename_is_valid(name
))
105 if (!string_is_safe(name
))