swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 56c02bd001154f95e7531dd5e0b5cfbe5e55fe30
parent 81cee7dfb814ef9bc20d3b7a4623f78c83ca015b
Author: Michael Forney <mforney@mforney.org>
Date:   Sat,  8 Feb 2014 00:38:06 -0800

xkb: Don't use unnecessary code-block

Diffstat:
Mlibswc/xkb.c | 74+++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 35 insertions(+), 39 deletions(-)

diff --git a/libswc/xkb.c b/libswc/xkb.c @@ -91,7 +91,10 @@ void swc_xkb_finalize(struct swc_xkb * xkb) bool swc_xkb_update_keymap(struct swc_xkb * xkb) { + const char * keymap_directory = getenv("XDG_RUNTIME_DIR") ?: "/tmp"; char * keymap_string; + char keymap_path[strlen(keymap_directory) + 1 + + sizeof keymap_file_template]; xkb->indices.ctrl = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_CTRL); @@ -102,55 +105,48 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb) xkb->indices.shift = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_SHIFT); - /* Keymap string */ - { - const char * keymap_directory = getenv("XDG_RUNTIME_DIR") ?: "/tmp"; - char keymap_path[strlen(keymap_directory) + 1 - + sizeof keymap_file_template]; - - /* In order to send the keymap to clients, we must first convert it to a - * string and then mmap it to a file. */ - keymap_string = xkb_keymap_get_as_string(xkb->keymap.map, - XKB_KEYMAP_FORMAT_TEXT_V1); + /* In order to send the keymap to clients, we must first convert it to a + * string and then mmap it to a file. */ + keymap_string = xkb_keymap_get_as_string(xkb->keymap.map, + XKB_KEYMAP_FORMAT_TEXT_V1); - if (!keymap_string) - { - printf("could not get XKB keymap as a string\n"); - goto error0; - } + if (!keymap_string) + { + printf("could not get XKB keymap as a string\n"); + goto error0; + } - sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template); + sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template); - xkb->keymap.size = strlen(keymap_string) + 1; - xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC); + xkb->keymap.size = strlen(keymap_string) + 1; + xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC); - if (xkb->keymap.fd == -1) - { - printf("could not create XKB keymap file\n"); - goto error1; - } + if (xkb->keymap.fd == -1) + { + printf("could not create XKB keymap file\n"); + goto error1; + } - unlink(keymap_path); + unlink(keymap_path); - if (posix_fallocate(xkb->keymap.fd, 0, xkb->keymap.size) != 0) - { - printf("could not resize XKB keymap file\n"); - goto error2; - } + if (posix_fallocate(xkb->keymap.fd, 0, xkb->keymap.size) != 0) + { + printf("could not resize XKB keymap file\n"); + goto error2; + } - xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE, - MAP_SHARED, xkb->keymap.fd, 0); + xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE, + MAP_SHARED, xkb->keymap.fd, 0); - if (xkb->keymap.area == MAP_FAILED) - { - printf("could not mmap XKB keymap string\n"); - goto error2; - } + if (xkb->keymap.area == MAP_FAILED) + { + printf("could not mmap XKB keymap string\n"); + goto error2; + } - strcpy(xkb->keymap.area, keymap_string); + strcpy(xkb->keymap.area, keymap_string); - free(keymap_string); - } + free(keymap_string); return true;