alist.c revision 5aefb6555731130ca4fd295960123d71f2d21fe8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sgs.h>
#include <string.h>
/*
* Alist manipulation. An Alist is a list of elements formed into an array.
* Traversal of the list is an array scan, which because of the locality of
* each reference is probably more efficient than a link-list traversal.
*
* The elements of an Alist are variable length. They can be pointers to
* other data structures, or data structures themselves. Traversal of an Alist
* thus returns a pointer to each data element.
*
* Alist elements can be deleted. This involve sliding any following elements
* over the element being deleted. ALIST_TRAVERSE() may be employed to traverse
* the list, at the same time elements are being deleted. Therefore, the next
* element is always determined as an offset from the beginning of the list.
*/
void *
{
void * new;
if (alp == 0) {
/*
* First time here, allocate a new Alist. Note that the Alist
* al_desc[] entry accounts for one void * already.
*/
return (0);
/*
* The list is full, add another block of elements. Determine
* the present number of elements and double them.
*/
sizeof (void *));
return (0);
}
/*
* If a data item has been provided, initialize the current alist entry
* with this item. Otherwise, initialize the entry to zero, presumably
* the caller will fill this in.
*/
if (item)
else
return (new);
}
/*
* Delete an element from an Alist. If a count is provided then the caller
* already knows what element to remove. Return a decremented count value so
* that the caller can continue an ALIST_TRAVERSE scan.
*/
int
{
void *addr;
if (offp) {
} else {
break;
}
}
return (0);
/*
* If the element to be removed is not the last entry of the array,
* slide the following elements over the present element.
*/
}
/*
* Reset the new offset, and decrement the callers count control
* variable if necessary. Null out the old tail element.
*/
if (offp)
return (1);
}
/*
* Generic alist test and append routine.
*/
int
{
void ** ipp;
return (ALE_EXISTS);
} else {
return (ALE_EXISTS);
}
}
if (cnt) {
return (0);
}
return (ALE_CREATE);
}