From 6b1602d426a07dfc8ecec878d1abcbb997c42f54 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Sun, 26 Aug 2007 09:18:36 +0000 Subject: [PATCH] can set NULL to name and property to have nly the index --- libconfig/config_get_next_property.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libconfig/config_get_next_property.c b/libconfig/config_get_next_property.c index 267355a..fd5eeff 100644 --- a/libconfig/config_get_next_property.c +++ b/libconfig/config_get_next_property.c @@ -50,23 +50,30 @@ int config_get_next_property(char *configuration, int index, char *name, char *p next_line = read_line(next_line); current_name = config_read_word(next_word, &next_word); - strncpy(name, current_name, next_word - current_name); - name[next_word - current_name] = 0; + if (name) + { + strncpy(name, current_name, next_word - current_name); + name[next_word - current_name] = 0; + } current_property = config_read_word(next_word, &next_word); - if (next_line - current_property != 0) + if (property) { - strncpy(property, current_property, next_line - current_property); + if (next_line - current_property != 0) + { + strncpy(property, current_property, + next_line - current_property); - /* remove '\n' if needed */ + /* remove '\n' if needed */ - if (*(next_line - 1) == '\n') - property[next_line - current_property - 1] = 0; + if (*(next_line - 1) == '\n') + property[next_line - current_property - 1] = 0; + else + property[next_line - current_property] = 0; + } else - property[next_line - current_property] = 0; + *property = 0; } - else - *property = 0; return next_line - (char*)configuration; }