Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/common/set.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2010-10-15 12:31:11 +0200
committerArthur de Jong <arthur@arthurdejong.org>2010-10-15 12:31:11 +0200
commitf6bbbc5da9d72ec6637ef8fea58c73686abdace1 (patch)
tree523ca9a9ab64a3d5bd3623b51ad2bf50a556faf3 /common/set.c
parente6100f8a81d178f1307571a5773931dd976986c2 (diff)
implement dict_getany() and set_pop() functions to be able to pick and remove entries
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1279 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'common/set.c')
-rw-r--r--common/set.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/common/set.c b/common/set.c
index d36ce2d..aec7e83 100644
--- a/common/set.c
+++ b/common/set.c
@@ -2,7 +2,7 @@
set.c - set functions
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2008, 2009 Arthur de Jong
+ Copyright (C) 2008, 2009, 2010 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
@@ -46,6 +46,19 @@ int set_add(SET *set,const char *value)
return dict_put((DICT *)set,value,set);
}
+char *set_pop(SET *set)
+{
+ const char *key;
+ char *value;
+ key=dict_getany((DICT *)set);
+ if (key==NULL)
+ return NULL; /* no more entries in set */
+ /* remove the entry from the dict and return a copy */
+ value=strdup(key);
+ dict_put((DICT *)set,key,NULL);
+ return value;
+}
+
int set_contains(SET *set,const char *value)
{
return dict_get((DICT *)set,value)!=NULL;