diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2008-04-17 21:12:21 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2008-04-17 21:12:21 +0000 |
commit | 2e48b85903b04117f9314b9ed69f0ac2d4d78356 (patch) | |
tree | 3414b0f55788c52c3ed8da25977ddb632a3f0c4e /common | |
parent | 15b3f8bc5a757d984e5510fdaec46196d8939a56 (diff) |
change dict_values_first() and dict_values_next() into dict_loop_first() and dict_loop_next() to have a looping mechanism over keys and values
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@675 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'common')
-rw-r--r-- | common/dict.c | 12 | ||||
-rw-r--r-- | common/dict.h | 18 |
2 files changed, 18 insertions, 12 deletions
diff --git a/common/dict.c b/common/dict.c index b6e54cf..70c746a 100644 --- a/common/dict.c +++ b/common/dict.c @@ -2,7 +2,7 @@ dict.c - dictionary functions This file is part of the nss-ldapd library. - Copyright (C) 2007 Arthur de Jong + Copyright (C) 2007, 2008 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -141,12 +141,12 @@ void dict_free(DICT *dict) free(dict); } -void dict_values_first(DICT *dict) +void dict_loop_first(DICT *dict) { dict->ptr=dict->head; } -void *dict_values_next(DICT *dict) +const char *dict_loop_next(DICT *dict,const char **key,void **value) { struct dict_entry *ptr; ptr=dict->ptr; @@ -157,8 +157,12 @@ void *dict_values_next(DICT *dict) if (ptr==NULL) { dict->ptr=NULL; + if (key!=NULL) *key=NULL; + if (value!=NULL) *value=NULL; return NULL; } dict->ptr=ptr->next; - return ptr->value; + if (key!=NULL) *key=ptr->key; + if (value!=NULL) *value=ptr->value; + return ptr->key; } diff --git a/common/dict.h b/common/dict.h index c91c901..c34ecc2 100644 --- a/common/dict.h +++ b/common/dict.h @@ -2,7 +2,7 @@ dict.h - dictionary functions This file is part of the nss-ldapd library. - Copyright (C) 2007 Arthur de Jong + Copyright (C) 2007, 2008 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -57,15 +57,17 @@ void *dict_get(DICT *dict,const char *key) for the dictionary and the keys is freed. */ void dict_free(DICT *dict); -/* Function for looping over all dictionary values. +/* Function for looping over all dictionary keys and values. This resets the search to the beginning of the dictionary. - This is required before calling dict_values_next(); */ -void dict_values_first(DICT *dict); + This is required before calling dict_loop_next(); */ +void dict_loop_first(DICT *dict); -/* Function for looping over all dictionary values. - This returns a stored value. NULL is returned when all - stored values have been returned. */ -void *dict_values_next(DICT *dict) +/* Function for looping over all dictionary keys and values. + This returns a stored key. NULL is returned when all + keys have been returned. The key and value are + stored in the key and value parameters if they aren't + NULL. */ +const char *dict_loop_next(DICT *dict,const char **key,void **value) MUST_USE; #endif /* _DICT_H */ |