Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jul 7, 2016
1 parent 435e952 commit 23ea040
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/usb_moded-config.c
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 23ea040

Please sign in to comment.