From 23ea040347823c5bff8d03caf73ecfd7ef56f865 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Wed, 6 Jul 2016 15:32:31 +0300 Subject: [PATCH] [config] Reverse the meaning of config_value_changed() return value Having a predicate function with name xxx_changed() that returns a non-zero value when nothing has changed is confusing. Switch the return value meaning so that non-zero means there is a difference and zero that there is not. Also treat old value of NULL and new value of NULL as no change. Signed-off-by: Simo Piiroinen --- src/usb_moded-config.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/usb_moded-config.c b/src/usb_moded-config.c index d8997eb..423cf0a 100644 --- a/src/usb_moded-config.c +++ b/src/usb_moded-config.c @@ -355,22 +355,14 @@ char * get_mode_setting(void) * @param key: key value of the entry we want to read * @new_value: potentially new value we want to compare against * - * @return: 1 when the old value is the same as the new one, 0 otherwise + * @return: 0 when the old value is the same as the new one, 1 otherwise */ int config_value_changed(GKeyFile *settingsfile, const char *entry, const char *key, const char *new_value) { - char *old = g_key_file_get_string(settingsfile, entry, key, NULL); - if (old) - { - gboolean unchanged = (g_strcmp0(old, new_value) == 0); - g_free(old); - if (unchanged) - { - return 1; - } - } - - return 0; + char *old_value = g_key_file_get_string(settingsfile, entry, key, NULL); + int changed = (g_strcmp0(old_value, new_value) != 0); + g_free(old_value); + return changed; } set_config_result_t set_config_setting(const char *entry, const char *key, const char *value) @@ -384,7 +376,7 @@ set_config_result_t set_config_setting(const char *entry, const char *key, const test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL); if(test) { - if(config_value_changed(settingsfile, entry, key, value)) + if(!config_value_changed(settingsfile, entry, key, value)) { g_key_file_free(settingsfile); return SET_CONFIG_UNCHANGED; @@ -537,7 +529,7 @@ set_config_result_t set_network_setting(const char *config, const char *setting) set_config_result_t ret = SET_CONFIG_ERROR; if (test) { - if(config_value_changed(settingsfile, NETWORK_ENTRY, config, setting)) + if(!config_value_changed(settingsfile, NETWORK_ENTRY, config, setting)) { g_key_file_free(settingsfile); return SET_CONFIG_UNCHANGED;