Merge commit '7e3488dc6cdcb0c04e1ce167a1a3bfef83b5f2e0'
[unleashed.git] / include / sys / group.h
blob2db1ac01bbe2a6a9d15bf424e8c0f6e7cbbbd41d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _GROUP_H
27 #define _GROUP_H
30 * Group Abstraction
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #if (defined(_KERNEL) || defined(_KMEMUSER))
38 #include <sys/types.h>
40 #define GRP_RESIZE 0x1 /* Resize group capacity if needed */
41 #define GRP_NORESIZE 0x2 /* Do not resize group capacity; may fail */
44 * group structure
46 typedef struct group {
47 uint_t grp_size; /* # of elements */
48 uint_t grp_capacity; /* current group capacity */
49 void **grp_set; /* element vector */
50 } group_t;
52 typedef uint_t group_iter_t;
56 * Return the number of elements in the group
58 #define GROUP_SIZE(grp) ((grp)->grp_size)
61 * Access the element at the specified group index
63 #define GROUP_ACCESS(grp, index) ((grp)->grp_set[index])
66 * Group creation / destruction
68 void group_create(group_t *);
69 void group_destroy(group_t *);
72 * Expand a group's holding capacity
74 void group_expand(group_t *, uint_t);
77 * Group element iteration
79 void group_iter_init(group_iter_t *);
80 void *group_iterate(group_t *, group_iter_t *);
83 * Add / remove an element (or elements) from the group
85 int group_add(group_t *, void *, int);
86 int group_remove(group_t *, void *, int);
87 void group_empty(group_t *);
90 * Add / remove / access an element at a specified index.
91 * The group must already have sufficient capacity to hold
92 * an element at the specified index.
94 int group_add_at(group_t *, void *, uint_t);
95 void group_remove_at(group_t *, uint_t);
98 * Search for an element in a group.
99 * Returns an index that may be used with the *_at()
100 * routines above to add or remove the element.
102 uint_t group_find(group_t *, void *);
105 * Convert a group to a string with list of integers.
107 * The consecutive integer values are represented using x-y notation.
108 * The resulting string looks like "1,2-5,8"
110 * The convert argument is used to map group elements to integer IDs.
111 * The output buffer and its length are specfied in the arguments.
113 extern char *group2intlist(group_t *, char *, size_t, int (convert)(void*));
115 #endif /* !_KERNEL && !_KMEMUSER */
117 #ifdef __cplusplus
119 #endif
121 #endif /* _GROUP_H */