From 4a048abd925e066dc7c995a8cbecf5628813df81 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Jul 2014 11:24:27 +0200 Subject: [PATCH] screen_keydef: save keys to path specified by --key-file Implements Mantis ticket 0004022. --- NEWS | 1 + src/screen_keydef.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 187b72c..be63b36 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ncmpc 0.24 - not yet released * fix crash on "jump" (hotkey ".") +* save keys to path specified by --key-file ncmpc 0.23 - (2014-07-10) diff --git a/src/screen_keydef.c b/src/screen_keydef.c index b947dd8..c89437e 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -25,6 +25,7 @@ #include "conf.h" #include "screen.h" #include "screen_utils.h" +#include "options.h" #include "Compiler.h" #include @@ -145,19 +146,24 @@ apply_keys(void) static int save_keys(void) { - if (!check_user_conf_dir()) { - screen_status_printf(_("Error: Unable to create directory ~/.ncmpc - %s"), - strerror(errno)); - screen_bell(); - return -1; + char *allocated = NULL; + const char *filename = options.key_file; + if (filename == NULL) { + if (!check_user_conf_dir()) { + screen_status_printf(_("Error: Unable to create directory ~/.ncmpc - %s"), + strerror(errno)); + screen_bell(); + return -1; + } + + filename = allocated = build_user_key_binding_filename(); } - char *filename = build_user_key_binding_filename(); FILE *f = fopen(filename, "w"); if (f == NULL) { screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); screen_bell(); - g_free(filename); + g_free(allocated); return -1; } @@ -166,7 +172,7 @@ save_keys(void) else screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); - g_free(filename); + g_free(allocated); return fclose(f); } -- 2.30.2