X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fscreen_keydef.c;h=c89437e03e90f98914fa3ff7028501fc7e34848c;hb=d3fa4666911bae9b7317b04cc6f286849b58db50;hp=dde5ce571321e56f8aebd75500a264424775799e;hpb=d4007f2eef7bf32498ad4233d8115c9e2c48b2c1;p=ncmpc.git diff --git a/src/screen_keydef.c b/src/screen_keydef.c index dde5ce5..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,28 +146,33 @@ 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; } if (write_key_bindings(f, KEYDEF_WRITE_HEADER)) - screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); - else screen_status_printf(_("Wrote %s"), filename); + else + screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); - g_free(filename); + g_free(allocated); return fclose(f); }