1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * 24*0Sstevel@tonic-gate * flist.c 25*0Sstevel@tonic-gate * 26*0Sstevel@tonic-gate * Defines the flist class. 27*0Sstevel@tonic-gate */ 28*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 29*0Sstevel@tonic-gate /* Copyright (c) 1994 by Sun Microsystems, Inc. */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <stdio.h> 32*0Sstevel@tonic-gate #include <stdlib.h> 33*0Sstevel@tonic-gate #include "flist.h" 34*0Sstevel@tonic-gate #include "mdbug.h" 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate /* 37*0Sstevel@tonic-gate * 38*0Sstevel@tonic-gate * flist_create 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * Description: 41*0Sstevel@tonic-gate * Constructor for the flist class. 42*0Sstevel@tonic-gate * Arguments: 43*0Sstevel@tonic-gate * Returns: 44*0Sstevel@tonic-gate * Preconditions: 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate flist_object_t * flist_create()47*0Sstevel@tonic-gateflist_create() 48*0Sstevel@tonic-gate { 49*0Sstevel@tonic-gate flist_object_t *flist_object_p; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate flist_object_p = (flist_object_t *)calloc(sizeof (flist_object_t), 1); 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate if (flist_object_p == NULL) 54*0Sstevel@tonic-gate doabort(); 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate flist_object_p->f_count = 0; 57*0Sstevel@tonic-gate flist_object_p->f_index = 0; 58*0Sstevel@tonic-gate return (flist_object_p); 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * 63*0Sstevel@tonic-gate * flist_destroy 64*0Sstevel@tonic-gate * 65*0Sstevel@tonic-gate * Description: 66*0Sstevel@tonic-gate * Destructor for the flist class. 67*0Sstevel@tonic-gate * Arguments: 68*0Sstevel@tonic-gate * Returns: 69*0Sstevel@tonic-gate * Preconditions: 70*0Sstevel@tonic-gate */ 71*0Sstevel@tonic-gate void flist_destroy(flist_object_t * flist_object_p)72*0Sstevel@tonic-gateflist_destroy(flist_object_t *flist_object_p) 73*0Sstevel@tonic-gate { 74*0Sstevel@tonic-gate free(flist_object_p); 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate /* 77*0Sstevel@tonic-gate * 78*0Sstevel@tonic-gate * fl_push 79*0Sstevel@tonic-gate * 80*0Sstevel@tonic-gate * Description: 81*0Sstevel@tonic-gate * Adds the specified pointer to the top of the list 82*0Sstevel@tonic-gate * if there is room. If there is no more room then 83*0Sstevel@tonic-gate * nothing happens. 84*0Sstevel@tonic-gate * Arguments: 85*0Sstevel@tonic-gate * Returns: 86*0Sstevel@tonic-gate * Preconditions: 87*0Sstevel@tonic-gate */ 88*0Sstevel@tonic-gate void fl_push(flist_object_t * flist_object_p,void * ptr)89*0Sstevel@tonic-gatefl_push(flist_object_t *flist_object_p, void *ptr) 90*0Sstevel@tonic-gate { 91*0Sstevel@tonic-gate if (flist_object_p->f_count < FLIST_SIZE) { 92*0Sstevel@tonic-gate flist_object_p->f_items[flist_object_p->f_count] = (char *)ptr; 93*0Sstevel@tonic-gate flist_object_p->f_count++; 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate /* 98*0Sstevel@tonic-gate * 99*0Sstevel@tonic-gate * fl_pop 100*0Sstevel@tonic-gate * 101*0Sstevel@tonic-gate * Description: 102*0Sstevel@tonic-gate * Removes the top item from the list. 103*0Sstevel@tonic-gate * No action is taken if the list is empty. 104*0Sstevel@tonic-gate * Arguments: 105*0Sstevel@tonic-gate * Returns: 106*0Sstevel@tonic-gate * Preconditions: 107*0Sstevel@tonic-gate */ 108*0Sstevel@tonic-gate void fl_pop(flist_object_t * flist_object_p)109*0Sstevel@tonic-gatefl_pop(flist_object_t *flist_object_p) 110*0Sstevel@tonic-gate { 111*0Sstevel@tonic-gate if (flist_object_p->f_count > 0) 112*0Sstevel@tonic-gate flist_object_p->f_count--; 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * 117*0Sstevel@tonic-gate * fl_top 118*0Sstevel@tonic-gate * 119*0Sstevel@tonic-gate * Description: 120*0Sstevel@tonic-gate * Returns the top item on the list. 121*0Sstevel@tonic-gate * Sets the internal state so that a following call to 122*0Sstevel@tonic-gate * next() will return the second item on the list. 123*0Sstevel@tonic-gate * Returns NULL if the list is empty. 124*0Sstevel@tonic-gate * Arguments: 125*0Sstevel@tonic-gate * Returns: 126*0Sstevel@tonic-gate * Preconditions: 127*0Sstevel@tonic-gate */ 128*0Sstevel@tonic-gate void * fl_top(flist_object_t * flist_object_p)129*0Sstevel@tonic-gatefl_top(flist_object_t *flist_object_p) 130*0Sstevel@tonic-gate { 131*0Sstevel@tonic-gate flist_object_p->f_index = flist_object_p->f_count; 132*0Sstevel@tonic-gate return (fl_next(flist_object_p)); 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate /* 136*0Sstevel@tonic-gate * 137*0Sstevel@tonic-gate * fl_next 138*0Sstevel@tonic-gate * 139*0Sstevel@tonic-gate * Description: 140*0Sstevel@tonic-gate * Returns the next item on the list. NULL if there 141*0Sstevel@tonic-gate * is no next item. 142*0Sstevel@tonic-gate * Arguments: 143*0Sstevel@tonic-gate * Returns: 144*0Sstevel@tonic-gate * Preconditions: 145*0Sstevel@tonic-gate */ 146*0Sstevel@tonic-gate void * fl_next(flist_object_t * flist_object_p)147*0Sstevel@tonic-gatefl_next(flist_object_t *flist_object_p) 148*0Sstevel@tonic-gate { 149*0Sstevel@tonic-gate if (flist_object_p->f_index > 0) { 150*0Sstevel@tonic-gate flist_object_p->f_index--; 151*0Sstevel@tonic-gate return (flist_object_p->f_items[ flist_object_p->f_index ]); 152*0Sstevel@tonic-gate } else { 153*0Sstevel@tonic-gate return (NULL); 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate /* 158*0Sstevel@tonic-gate * 159*0Sstevel@tonic-gate * fl_clear 160*0Sstevel@tonic-gate * 161*0Sstevel@tonic-gate * Description: 162*0Sstevel@tonic-gate * Removes all items from the list and frees them. 163*0Sstevel@tonic-gate * Arguments: 164*0Sstevel@tonic-gate * Returns: 165*0Sstevel@tonic-gate * Preconditions: 166*0Sstevel@tonic-gate */ 167*0Sstevel@tonic-gate void fl_clear(flist_object_t * flist_object_p)168*0Sstevel@tonic-gatefl_clear(flist_object_t *flist_object_p) 169*0Sstevel@tonic-gate { 170*0Sstevel@tonic-gate void *p1; 171*0Sstevel@tonic-gate while ((p1 = fl_top(flist_object_p)) != NULL) { 172*0Sstevel@tonic-gate free(p1); 173*0Sstevel@tonic-gate fl_pop(flist_object_p); 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate /* 177*0Sstevel@tonic-gate * 178*0Sstevel@tonic-gate * fl_space 179*0Sstevel@tonic-gate * 180*0Sstevel@tonic-gate * Description: 181*0Sstevel@tonic-gate * Arguments: 182*0Sstevel@tonic-gate * Returns: 183*0Sstevel@tonic-gate * Returns the number of free slots on the list. 184*0Sstevel@tonic-gate * Errors: 185*0Sstevel@tonic-gate * Preconditions: 186*0Sstevel@tonic-gate */ 187*0Sstevel@tonic-gate int fl_space(flist_object_t * flist_object_p)188*0Sstevel@tonic-gatefl_space(flist_object_t *flist_object_p) 189*0Sstevel@tonic-gate { 190*0Sstevel@tonic-gate return (FLIST_SIZE - flist_object_p->f_count); 191*0Sstevel@tonic-gate } 192