Commit 23ea0403 authored by spiiroin's avatar spiiroin

[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: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 435e952b
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment