From d9d6867a57104da31d6b6fe77fb17e2ebb7422cf Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 31 Aug 2007 20:42:27 +0000 Subject: [PATCH] functions return index if possible --- libconfig/config_add_property.c | 4 +++- libconfig/config_get_indexed_property.c | 5 +---- libconfig/config_remove_indexed_property.c | 6 ++++-- libconfig/config_remove_property.c | 4 ++-- libconfig/config_set_indexed_property.c | 4 +++- libconfig/config_set_property.c | 5 +++-- libconfig/libconfig.h | 10 +++++----- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libconfig/config_add_property.c b/libconfig/config_add_property.c index ab83adb..103e9d2 100644 --- a/libconfig/config_add_property.c +++ b/libconfig/config_add_property.c @@ -9,7 +9,7 @@ #include "libconfig.h" -void config_add_property(char* configuration, char* name, char* property) +int config_add_property(char* configuration, char* name, char* property) { int index = strlen(configuration); @@ -20,4 +20,6 @@ void config_add_property(char* configuration, char* name, char* property) } sprintf(configuration + index, "%s %s", name, property); + + return index; } diff --git a/libconfig/config_get_indexed_property.c b/libconfig/config_get_indexed_property.c index 6168d17..5bafc05 100644 --- a/libconfig/config_get_indexed_property.c +++ b/libconfig/config_get_indexed_property.c @@ -16,8 +16,5 @@ int config_get_indexed_property(char *configuration, char *index_name, char *ind index = config_find_indexed_property(configuration, index_name, index_property, name, property); - if (index == -1) - return -1; - - return 0; + return index; } diff --git a/libconfig/config_remove_indexed_property.c b/libconfig/config_remove_indexed_property.c index 1f1e5e6..83aba50 100644 --- a/libconfig/config_remove_indexed_property.c +++ b/libconfig/config_remove_indexed_property.c @@ -9,7 +9,7 @@ #include "libconfig.h" -void config_remove_indexed_property(char *configuration, char *index_name, +int config_remove_indexed_property(char *configuration, char *index_name, char *index_property, char *name) { int last_index; @@ -19,7 +19,7 @@ void config_remove_indexed_property(char *configuration, char *index_name, last_index = config_find_indexed_property(configuration, index_name, index_property, name, NULL); if (last_index == -1) - return; + return -1; index = config_get_next_property(configuration, last_index, NULL, NULL); if (index != -1) @@ -31,4 +31,6 @@ void config_remove_indexed_property(char *configuration, char *index_name, if (configuration[index + len - 1] == '\n') len--; configuration[index + len] = 0; + + return last_index; } diff --git a/libconfig/config_remove_property.c b/libconfig/config_remove_property.c index 4769e14..8001cbd 100644 --- a/libconfig/config_remove_property.c +++ b/libconfig/config_remove_property.c @@ -9,7 +9,7 @@ #include "libconfig.h" -void config_remove_property(char *configuration, char *name) +int config_remove_property(char *configuration, char *name) { - config_remove_indexed_property(configuration, name, NULL, NULL); + return config_remove_indexed_property(configuration, name, NULL, NULL); } diff --git a/libconfig/config_set_indexed_property.c b/libconfig/config_set_indexed_property.c index cc89d4d..0c77ff0 100644 --- a/libconfig/config_set_indexed_property.c +++ b/libconfig/config_set_indexed_property.c @@ -9,7 +9,7 @@ #include "libconfig.h" -void config_set_indexed_property(char *configuration, +int config_set_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property) { @@ -80,4 +80,6 @@ void config_set_indexed_property(char *configuration, if (configuration[last_index + len - 1] == '\n') len--; configuration[last_index + len] = 0; + + return last_index; } diff --git a/libconfig/config_set_property.c b/libconfig/config_set_property.c index 3080806..b27632f 100644 --- a/libconfig/config_set_property.c +++ b/libconfig/config_set_property.c @@ -9,7 +9,8 @@ #include "libconfig.h" -void config_set_property(char *configuration, char *name, char *property) +int config_set_property(char *configuration, char *name, char *property) { - config_set_indexed_property(configuration, NULL, NULL, name, property); + return config_set_indexed_property(configuration, NULL, NULL, + name, property); } diff --git a/libconfig/libconfig.h b/libconfig/libconfig.h index 1185134..6355560 100644 --- a/libconfig/libconfig.h +++ b/libconfig/libconfig.h @@ -8,10 +8,10 @@ extern char *config_read_word(char *line, char **next); extern int config_get_next_property(char *configuration, int index, char *name, char *property); extern int config_get_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property); extern int config_get_property(char *configuration, char *name, char *property); -extern void config_remove_property(char *configuration, char *name); -extern void config_set_property(char *configuration, char *name, char *property); -extern void config_set_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property); -extern void config_remove_indexed_property(char *configuration, char *index_name, char *index_property, char *name); +extern int config_remove_property(char *configuration, char *name); +extern int config_set_property(char *configuration, char *name, char *property); +extern int config_set_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property); +extern int config_remove_indexed_property(char *configuration, char *index_name, char *index_property, char *name); extern int config_find_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property); extern int config_find_entry(char *configuration, char *name, char *property); -extern void config_add_property(char* configuration, char* name, char* property); +extern int config_add_property(char* configuration, char* name, char* property);