4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
26 * Defines the flist class.
28 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* Copyright (c) 1994 by Sun Microsystems, Inc. */
41 * Constructor for the flist class.
49 flist_object_t
*flist_object_p
;
51 flist_object_p
= (flist_object_t
*)calloc(sizeof (flist_object_t
), 1);
53 if (flist_object_p
== NULL
)
56 flist_object_p
->f_count
= 0;
57 flist_object_p
->f_index
= 0;
58 return (flist_object_p
);
66 * Destructor for the flist class.
72 flist_destroy(flist_object_t
*flist_object_p
)
81 * Adds the specified pointer to the top of the list
82 * if there is room. If there is no more room then
89 fl_push(flist_object_t
*flist_object_p
, void *ptr
)
91 if (flist_object_p
->f_count
< FLIST_SIZE
) {
92 flist_object_p
->f_items
[flist_object_p
->f_count
] = (char *)ptr
;
93 flist_object_p
->f_count
++;
102 * Removes the top item from the list.
103 * No action is taken if the list is empty.
109 fl_pop(flist_object_t
*flist_object_p
)
111 if (flist_object_p
->f_count
> 0)
112 flist_object_p
->f_count
--;
120 * Returns the top item on the list.
121 * Sets the internal state so that a following call to
122 * next() will return the second item on the list.
123 * Returns NULL if the list is empty.
129 fl_top(flist_object_t
*flist_object_p
)
131 flist_object_p
->f_index
= flist_object_p
->f_count
;
132 return (fl_next(flist_object_p
));
140 * Returns the next item on the list. NULL if there
147 fl_next(flist_object_t
*flist_object_p
)
149 if (flist_object_p
->f_index
> 0) {
150 flist_object_p
->f_index
--;
151 return (flist_object_p
->f_items
[ flist_object_p
->f_index
]);
162 * Removes all items from the list and frees them.
168 fl_clear(flist_object_t
*flist_object_p
)
171 while ((p1
= fl_top(flist_object_p
)) != NULL
) {
173 fl_pop(flist_object_p
);
183 * Returns the number of free slots on the list.
188 fl_space(flist_object_t
*flist_object_p
)
190 return (FLIST_SIZE
- flist_object_p
->f_count
);