From f6bbbc5da9d72ec6637ef8fea58c73686abdace1 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 15 Oct 2010 10:31:11 +0000 Subject: 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 --- common/set.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'common/set.c') 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; -- cgit v1.2.3