- /* Determine how well matching this entry is */
- if (streq_ptr(c->x11_layout, a[1]))
- /* If we got an exact match, this is best */
- matching = 10;
- else {
- size_t x;
-
- x = strcspn(c->x11_layout, ",");
-
- /* We have multiple X layouts, look
- * for an entry that matches our key
- * with the everything but the first
- * layout stripped off. */
- if (x > 0 &&
- strlen(a[1]) == x &&
- strneq(c->x11_layout, a[1], x))
- matching = 5;
- else {
- size_t w;
-
- /* If that didn't work, strip
- * off the other layouts from
- * the entry, too */
- w = strcspn(a[1], ",");
-
- if (x > 0 && x == w &&
- memcmp(c->x11_layout, a[1], x) == 0)
- matching = 1;
- }
+ f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
+ if (!f)
+ return -errno;
+
+ for (;;) {
+ _cleanup_strv_free_ char **a = NULL;
+ unsigned matching = 0;
+ int r;
+
+ r = read_next_mapping(f, &n, &a);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ break;
+
+ /* Determine how well matching this entry is */
+ if (streq_ptr(c->x11_layout, a[1]))
+ /* If we got an exact match, this is best */
+ matching = 10;
+ else {
+ size_t x;
+
+ x = strcspn(c->x11_layout, ",");
+
+ /* We have multiple X layouts, look for an
+ * entry that matches our key with everything
+ * but the first layout stripped off. */
+ if (x > 0 &&
+ strlen(a[1]) == x &&
+ strneq(c->x11_layout, a[1], x))
+ matching = 5;
+ else {
+ size_t w;
+
+ /* If that didn't work, strip off the
+ * other layouts from the entry, too */
+ w = strcspn(a[1], ",");
+
+ if (x > 0 && x == w &&
+ memcmp(c->x11_layout, a[1], x) == 0)
+ matching = 1;