diff options
author | Simon Ser <contact@emersion.fr> | 2023-02-28 16:43:05 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-04-14 18:34:54 +0200 |
commit | 08c1946d71039e583696842c3558b337aede1cbf (patch) | |
tree | 3873db2edfb31146bd6cd17dae63f068aef34f05 /sway/input/keyboard.c | |
parent | common/gesture: use format_str() (diff) | |
download | sway-08c1946d71039e583696842c3558b337aede1cbf.tar.gz sway-08c1946d71039e583696842c3558b337aede1cbf.tar.zst sway-08c1946d71039e583696842c3558b337aede1cbf.zip |
Use format_str() throughout
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 45a588ec..c3bf4fbb 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -717,23 +717,11 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
717 | 717 | ||
718 | static void handle_xkb_context_log(struct xkb_context *context, | 718 | static void handle_xkb_context_log(struct xkb_context *context, |
719 | enum xkb_log_level level, const char *format, va_list args) { | 719 | enum xkb_log_level level, const char *format, va_list args) { |
720 | va_list args_copy; | 720 | char *error = vformat_str(format, args); |
721 | va_copy(args_copy, args); | ||
722 | size_t length = vsnprintf(NULL, 0, format, args_copy) + 1; | ||
723 | va_end(args_copy); | ||
724 | |||
725 | char *error = malloc(length); | ||
726 | if (!error) { | ||
727 | sway_log(SWAY_ERROR, "Failed to allocate libxkbcommon log message"); | ||
728 | return; | ||
729 | } | ||
730 | 721 | ||
731 | va_copy(args_copy, args); | 722 | size_t len = strlen(error); |
732 | vsnprintf(error, length, format, args_copy); | 723 | if (error[len - 1] == '\n') { |
733 | va_end(args_copy); | 724 | error[len - 1] = '\0'; |
734 | |||
735 | if (error[length - 2] == '\n') { | ||
736 | error[length - 2] = '\0'; | ||
737 | } | 725 | } |
738 | 726 | ||
739 | sway_log_importance_t importance = SWAY_DEBUG; | 727 | sway_log_importance_t importance = SWAY_DEBUG; |
@@ -768,13 +756,8 @@ struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic, | |||
768 | if (!keymap_file) { | 756 | if (!keymap_file) { |
769 | sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file); | 757 | sway_log_errno(SWAY_ERROR, "cannot read xkb file %s", ic->xkb_file); |
770 | if (error) { | 758 | if (error) { |
771 | size_t len = snprintf(NULL, 0, "cannot read xkb file %s: %s", | 759 | *error = format_str("cannot read xkb file %s: %s", |
772 | ic->xkb_file, strerror(errno)) + 1; | 760 | ic->xkb_file, strerror(errno)); |
773 | *error = malloc(len); | ||
774 | if (*error) { | ||
775 | snprintf(*error, len, "cannot read xkb_file %s: %s", | ||
776 | ic->xkb_file, strerror(errno)); | ||
777 | } | ||
778 | } | 761 | } |
779 | goto cleanup; | 762 | goto cleanup; |
780 | } | 763 | } |