From: twisti Date: Fri, 17 Nov 2006 15:47:28 +0000 (+0000) Subject: * src/vm/properties.c (properties_add): Replace entry if it already X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=fda335310fed05944cb776186380e467f852ec0a;p=cacao.git * src/vm/properties.c (properties_add): Replace entry if it already exists. --- diff --git a/src/vm/properties.c b/src/vm/properties.c index 69582ec24..762696fc0 100644 --- a/src/vm/properties.c +++ b/src/vm/properties.c @@ -26,7 +26,7 @@ Authors: Christian Thalinger - $Id: properties.c 5991 2006-11-15 18:26:40Z twisti $ + $Id: properties.c 6014 2006-11-17 15:47:28Z twisti $ */ @@ -315,20 +315,36 @@ bool properties_postinit(void) /* properties_add ************************************************************** - Adds a property entry to the internal property list. + Adds a property entry to the internal property list. If there's + already an entry with the same key, replace it. *******************************************************************************/ void properties_add(char *key, char *value) { - list_properties_entry *p; + list_properties_entry *pe; + + /* search for the entry */ + + for (pe = list_first(list_properties); pe != NULL; + pe = list_next(list_properties, pe)) { + if (strcmp(pe->key, key) == 0) { + /* entry was found, replace the value */ + + pe->value = value; + + return; + } + } + + /* entry was not found, insert a new one */ - p = NEW(list_properties_entry); + pe = NEW(list_properties_entry); - p->key = key; - p->value = value; + pe->key = key; + pe->value = value; - list_add_last_unsynced(list_properties, p); + list_add_last_unsynced(list_properties, pe); }