|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
set.h - set functions
|
|
Packit |
6bd9ab |
This file is part of the nss-pam-ldapd library.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2008, 2009, 2010, 2012 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#ifndef COMMON__SET_H
|
|
Packit |
6bd9ab |
#define COMMON__SET_H
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include "compat/attrs.h"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
These functions provide a set of strings in an unordered
|
|
Packit |
6bd9ab |
collection.
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
typedef struct set SET;
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Create a new instance of a set. Returns NULL
|
|
Packit |
6bd9ab |
in case of memory allocation errors. */
|
|
Packit |
6bd9ab |
SET *set_new(void)
|
|
Packit |
6bd9ab |
LIKE_MALLOC MUST_USE;
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Add a string in the set. The value is duplicated
|
|
Packit |
6bd9ab |
and can be reused by the caller.
|
|
Packit |
6bd9ab |
This function returns non-zero in case of memory allocation
|
|
Packit |
6bd9ab |
errors. All value comparisons are case sensitive. */
|
|
Packit |
6bd9ab |
int set_add(SET *set, const char *value);
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Return non-zero if the value is in the set.
|
|
Packit |
6bd9ab |
All value comparisons are case sensitive. */
|
|
Packit |
6bd9ab |
int set_contains(SET *set, const char *value)
|
|
Packit |
6bd9ab |
MUST_USE;
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Get an element from the set and removes it from the set.
|
|
Packit |
6bd9ab |
Returns NULL on an empty set. A copy of the string in the set
|
|
Packit |
6bd9ab |
is returned, the caller should use free() to free it. */
|
|
Packit |
6bd9ab |
char *set_pop(SET *set);
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Remove the set from memory. All allocated storage
|
|
Packit |
6bd9ab |
for the set and the values is freed. */
|
|
Packit |
6bd9ab |
void set_free(SET *set);
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* Return the content of the set as a list of strings.
|
|
Packit |
6bd9ab |
The caller should free the memory with a single call to free(). */
|
|
Packit |
6bd9ab |
const char **set_tolist(SET *set)
|
|
Packit |
6bd9ab |
MUST_USE;
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#endif /* COMMON__SET_H */
|