xref: /titanic_44/usr/src/lib/libuutil/common/libuutil.h (revision 0b5c9250b17799ab6af5fd285c7f4a3ba5b97822)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*0b5c9250Shg115875  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_LIBUUTIL_H
287c478bd9Sstevel@tonic-gate #define	_LIBUUTIL_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <stdarg.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Standard flags codes.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #define	UU_DEFAULT		0
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Standard error codes.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #define	UU_ERROR_NONE		0	/* no error */
487c478bd9Sstevel@tonic-gate #define	UU_ERROR_INVALID_ARGUMENT 1	/* invalid argument */
497c478bd9Sstevel@tonic-gate #define	UU_ERROR_UNKNOWN_FLAG	2	/* passed flag invalid */
507c478bd9Sstevel@tonic-gate #define	UU_ERROR_NO_MEMORY	3	/* out of memory */
517c478bd9Sstevel@tonic-gate #define	UU_ERROR_CALLBACK_FAILED 4	/* callback-initiated error */
527c478bd9Sstevel@tonic-gate #define	UU_ERROR_NOT_SUPPORTED	5	/* operation not supported */
537c478bd9Sstevel@tonic-gate #define	UU_ERROR_EMPTY		6	/* no value provided */
547c478bd9Sstevel@tonic-gate #define	UU_ERROR_UNDERFLOW	7	/* value is too small */
557c478bd9Sstevel@tonic-gate #define	UU_ERROR_OVERFLOW	8	/* value is too value */
567c478bd9Sstevel@tonic-gate #define	UU_ERROR_INVALID_CHAR	9	/* value contains unexpected char */
577c478bd9Sstevel@tonic-gate #define	UU_ERROR_INVALID_DIGIT	10	/* value contains digit not in base */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	UU_ERROR_SYSTEM		99	/* underlying system error */
607c478bd9Sstevel@tonic-gate #define	UU_ERROR_UNKNOWN	100	/* error status not known */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Standard program exit codes.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate #define	UU_EXIT_OK	(*(uu_exit_ok()))
667c478bd9Sstevel@tonic-gate #define	UU_EXIT_FATAL	(*(uu_exit_fatal()))
677c478bd9Sstevel@tonic-gate #define	UU_EXIT_USAGE	(*(uu_exit_usage()))
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Exit status profiles.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	UU_PROFILE_DEFAULT	0
737c478bd9Sstevel@tonic-gate #define	UU_PROFILE_LAUNCHER	1
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Error reporting functions.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate uint32_t uu_error(void);
797c478bd9Sstevel@tonic-gate const char *uu_strerror(uint32_t);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Program notification functions.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate extern void uu_alt_exit(int);
857c478bd9Sstevel@tonic-gate extern const char *uu_setpname(char *);
867c478bd9Sstevel@tonic-gate extern const char *uu_getpname(void);
877c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
887c478bd9Sstevel@tonic-gate extern void uu_warn(const char *, ...);
897c478bd9Sstevel@tonic-gate extern void uu_vwarn(const char *, va_list);
907c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
91*0b5c9250Shg115875 extern void uu_die(const char *, ...) __NORETURN;
92*0b5c9250Shg115875 extern void uu_vdie(const char *, va_list) __NORETURN;
937c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
94*0b5c9250Shg115875 extern void uu_xdie(int, const char *, ...) __NORETURN;
95*0b5c9250Shg115875 extern void uu_vxdie(int, const char *, va_list) __NORETURN;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Exit status functions (not to be used directly)
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate extern int *uu_exit_ok(void);
1017c478bd9Sstevel@tonic-gate extern int *uu_exit_fatal(void);
1027c478bd9Sstevel@tonic-gate extern int *uu_exit_usage(void);
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * string->number conversions
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate extern int uu_strtoint(const char *, void *, size_t, int, int64_t, int64_t);
1087c478bd9Sstevel@tonic-gate extern int uu_strtouint(const char *, void *, size_t, int, uint64_t, uint64_t);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Debug print facility functions.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate typedef struct uu_dprintf uu_dprintf_t;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate typedef enum {
1167c478bd9Sstevel@tonic-gate 	UU_DPRINTF_SILENT,
1177c478bd9Sstevel@tonic-gate 	UU_DPRINTF_FATAL,
1187c478bd9Sstevel@tonic-gate 	UU_DPRINTF_WARNING,
1197c478bd9Sstevel@tonic-gate 	UU_DPRINTF_NOTICE,
1207c478bd9Sstevel@tonic-gate 	UU_DPRINTF_INFO,
1217c478bd9Sstevel@tonic-gate 	UU_DPRINTF_DEBUG
1227c478bd9Sstevel@tonic-gate } uu_dprintf_severity_t;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate extern uu_dprintf_t *uu_dprintf_create(const char *, uu_dprintf_severity_t,
1257c478bd9Sstevel@tonic-gate     uint_t);
1267c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/
1277c478bd9Sstevel@tonic-gate extern void uu_dprintf(uu_dprintf_t *, uu_dprintf_severity_t,
1287c478bd9Sstevel@tonic-gate     const char *, ...);
1297c478bd9Sstevel@tonic-gate extern void uu_dprintf_destroy(uu_dprintf_t *);
1307c478bd9Sstevel@tonic-gate extern const char *uu_dprintf_getname(uu_dprintf_t *);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Identifier test flags and function.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate #define	UU_NAME_DOMAIN		0x1	/* allow SUNW, or com.sun, prefix */
1367c478bd9Sstevel@tonic-gate #define	UU_NAME_PATH		0x2	/* allow '/'-delimited paths */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate int uu_check_name(const char *, uint_t);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * File creation functions.
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate extern int uu_open_tmp(const char *dir, uint_t uflags);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate  * Convenience functions.
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
1497c478bd9Sstevel@tonic-gate extern char *uu_msprintf(const char *format, ...);
1507c478bd9Sstevel@tonic-gate extern void *uu_zalloc(size_t);
1517c478bd9Sstevel@tonic-gate extern void uu_free(void *);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Comparison function type definition.
1557c478bd9Sstevel@tonic-gate  *   Developers should be careful in their use of the _private argument. If you
1567c478bd9Sstevel@tonic-gate  *   break interface guarantees, you get undefined behavior.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate typedef int uu_compare_fn_t(const void *__left, const void *__right,
1597c478bd9Sstevel@tonic-gate     void *__private);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Walk variant flags.
1637c478bd9Sstevel@tonic-gate  *   A data structure need not provide support for all variants and
1647c478bd9Sstevel@tonic-gate  *   combinations.  Refer to the appropriate documentation.
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate #define	UU_WALK_ROBUST		0x00000001	/* walk can survive removes */
1677c478bd9Sstevel@tonic-gate #define	UU_WALK_REVERSE		0x00000002	/* reverse walk order */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	UU_WALK_PREORDER	0x00000010	/* walk tree in pre-order */
1707c478bd9Sstevel@tonic-gate #define	UU_WALK_POSTORDER	0x00000020	/* walk tree in post-order */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * Walk callback function return codes.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate #define	UU_WALK_ERROR		-1
1767c478bd9Sstevel@tonic-gate #define	UU_WALK_NEXT		0
1777c478bd9Sstevel@tonic-gate #define	UU_WALK_DONE		1
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Walk callback function type definition.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate typedef int uu_walk_fn_t(void *_elem, void *_private);
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate  * lists: opaque structures
1867c478bd9Sstevel@tonic-gate  */
1877c478bd9Sstevel@tonic-gate typedef struct uu_list_pool uu_list_pool_t;
1887c478bd9Sstevel@tonic-gate typedef struct uu_list uu_list_t;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate typedef struct uu_list_node {
1917c478bd9Sstevel@tonic-gate 	uintptr_t uln_opaque[2];
1927c478bd9Sstevel@tonic-gate } uu_list_node_t;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate typedef struct uu_list_walk uu_list_walk_t;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate typedef uintptr_t uu_list_index_t;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate  * lists: interface
2007c478bd9Sstevel@tonic-gate  *
2017c478bd9Sstevel@tonic-gate  * basic usage:
2027c478bd9Sstevel@tonic-gate  *	typedef struct foo {
2037c478bd9Sstevel@tonic-gate  *		...
2047c478bd9Sstevel@tonic-gate  *		uu_list_node_t foo_node;
2057c478bd9Sstevel@tonic-gate  *		...
2067c478bd9Sstevel@tonic-gate  *	} foo_t;
2077c478bd9Sstevel@tonic-gate  *
2087c478bd9Sstevel@tonic-gate  *	static int
2097c478bd9Sstevel@tonic-gate  *	foo_compare(void *l_arg, void *r_arg, void *private)
2107c478bd9Sstevel@tonic-gate  *	{
2117c478bd9Sstevel@tonic-gate  *		foo_t *l = l_arg;
2127c478bd9Sstevel@tonic-gate  *		foo_t *r = r_arg;
2137c478bd9Sstevel@tonic-gate  *
2147c478bd9Sstevel@tonic-gate  *		if (... l greater than r ...)
2157c478bd9Sstevel@tonic-gate  *			return (1);
2167c478bd9Sstevel@tonic-gate  *		if (... l less than r ...)
2177c478bd9Sstevel@tonic-gate  *			return (-1);
2187c478bd9Sstevel@tonic-gate  *		return (0);
2197c478bd9Sstevel@tonic-gate  *	}
2207c478bd9Sstevel@tonic-gate  *
2217c478bd9Sstevel@tonic-gate  *	...
2227c478bd9Sstevel@tonic-gate  *		// at initialization time
2237c478bd9Sstevel@tonic-gate  *		foo_pool = uu_list_pool_create("foo_pool",
2247c478bd9Sstevel@tonic-gate  *		    sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare,
2257c478bd9Sstevel@tonic-gate  *		    debugging? 0 : UU_AVL_POOL_DEBUG);
2267c478bd9Sstevel@tonic-gate  *	...
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate uu_list_pool_t *uu_list_pool_create(const char *, size_t, size_t,
2297c478bd9Sstevel@tonic-gate     uu_compare_fn_t *, uint32_t);
2307c478bd9Sstevel@tonic-gate #define	UU_LIST_POOL_DEBUG	0x00000001
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate void uu_list_pool_destroy(uu_list_pool_t *);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * usage:
2367c478bd9Sstevel@tonic-gate  *
2377c478bd9Sstevel@tonic-gate  *	foo_t *a;
2387c478bd9Sstevel@tonic-gate  *	a = malloc(sizeof(*a));
2397c478bd9Sstevel@tonic-gate  *	uu_list_node_init(a, &a->foo_list, pool);
2407c478bd9Sstevel@tonic-gate  *	...
2417c478bd9Sstevel@tonic-gate  *	uu_list_node_fini(a, &a->foo_list, pool);
2427c478bd9Sstevel@tonic-gate  *	free(a);
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate void uu_list_node_init(void *, uu_list_node_t *, uu_list_pool_t *);
2457c478bd9Sstevel@tonic-gate void uu_list_node_fini(void *, uu_list_node_t *, uu_list_pool_t *);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate uu_list_t *uu_list_create(uu_list_pool_t *, void *_parent, uint32_t);
2487c478bd9Sstevel@tonic-gate #define	UU_LIST_DEBUG	0x00000001
2497c478bd9Sstevel@tonic-gate #define	UU_LIST_SORTED	0x00000002	/* list is sorted */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate void uu_list_destroy(uu_list_t *);	/* list must be empty */
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate size_t uu_list_numnodes(uu_list_t *);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate void *uu_list_first(uu_list_t *);
2567c478bd9Sstevel@tonic-gate void *uu_list_last(uu_list_t *);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate void *uu_list_next(uu_list_t *, void *);
2597c478bd9Sstevel@tonic-gate void *uu_list_prev(uu_list_t *, void *);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate int uu_list_walk(uu_list_t *, uu_walk_fn_t *, void *, uint32_t);
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate uu_list_walk_t *uu_list_walk_start(uu_list_t *, uint32_t);
2647c478bd9Sstevel@tonic-gate void *uu_list_walk_next(uu_list_walk_t *);
2657c478bd9Sstevel@tonic-gate void uu_list_walk_end(uu_list_walk_t *);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate void *uu_list_find(uu_list_t *, void *, void *, uu_list_index_t *);
2687c478bd9Sstevel@tonic-gate void uu_list_insert(uu_list_t *, void *, uu_list_index_t);
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate void *uu_list_nearest_next(uu_list_t *, uu_list_index_t);
2717c478bd9Sstevel@tonic-gate void *uu_list_nearest_prev(uu_list_t *, uu_list_index_t);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate void *uu_list_teardown(uu_list_t *, void **);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate void uu_list_remove(uu_list_t *, void *);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate /*
2787c478bd9Sstevel@tonic-gate  * lists: interfaces for non-sorted lists only
2797c478bd9Sstevel@tonic-gate  */
2807c478bd9Sstevel@tonic-gate int uu_list_insert_before(uu_list_t *, void *_target, void *_elem);
2817c478bd9Sstevel@tonic-gate int uu_list_insert_after(uu_list_t *, void *_target, void *_elem);
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate  * avl trees: opaque structures
2857c478bd9Sstevel@tonic-gate  */
2867c478bd9Sstevel@tonic-gate typedef struct uu_avl_pool uu_avl_pool_t;
2877c478bd9Sstevel@tonic-gate typedef struct uu_avl uu_avl_t;
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate typedef struct uu_avl_node {
2907c478bd9Sstevel@tonic-gate #ifdef _LP64
2917c478bd9Sstevel@tonic-gate 	uintptr_t uan_opaque[3];
2927c478bd9Sstevel@tonic-gate #else
2937c478bd9Sstevel@tonic-gate 	uintptr_t uan_opaque[4];
2947c478bd9Sstevel@tonic-gate #endif
2957c478bd9Sstevel@tonic-gate } uu_avl_node_t;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate typedef struct uu_avl_walk uu_avl_walk_t;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate typedef uintptr_t uu_avl_index_t;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate /*
3027c478bd9Sstevel@tonic-gate  * avl trees: interface
3037c478bd9Sstevel@tonic-gate  *
3047c478bd9Sstevel@tonic-gate  * basic usage:
3057c478bd9Sstevel@tonic-gate  *	typedef struct foo {
3067c478bd9Sstevel@tonic-gate  *		...
3077c478bd9Sstevel@tonic-gate  *		uu_avl_node_t foo_node;
3087c478bd9Sstevel@tonic-gate  *		...
3097c478bd9Sstevel@tonic-gate  *	} foo_t;
3107c478bd9Sstevel@tonic-gate  *
3117c478bd9Sstevel@tonic-gate  *	static int
3127c478bd9Sstevel@tonic-gate  *	foo_compare(void *l_arg, void *r_arg, void *private)
3137c478bd9Sstevel@tonic-gate  *	{
3147c478bd9Sstevel@tonic-gate  *		foo_t *l = l_arg;
3157c478bd9Sstevel@tonic-gate  *		foo_t *r = r_arg;
3167c478bd9Sstevel@tonic-gate  *
3177c478bd9Sstevel@tonic-gate  *		if (... l greater than r ...)
3187c478bd9Sstevel@tonic-gate  *			return (1);
3197c478bd9Sstevel@tonic-gate  *		if (... l less than r ...)
3207c478bd9Sstevel@tonic-gate  *			return (-1);
3217c478bd9Sstevel@tonic-gate  *		return (0);
3227c478bd9Sstevel@tonic-gate  *	}
3237c478bd9Sstevel@tonic-gate  *
3247c478bd9Sstevel@tonic-gate  *	...
3257c478bd9Sstevel@tonic-gate  *		// at initialization time
3267c478bd9Sstevel@tonic-gate  *		foo_pool = uu_avl_pool_create("foo_pool",
3277c478bd9Sstevel@tonic-gate  *		    sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare,
3287c478bd9Sstevel@tonic-gate  *		    debugging? 0 : UU_AVL_POOL_DEBUG);
3297c478bd9Sstevel@tonic-gate  *	...
3307c478bd9Sstevel@tonic-gate  */
3317c478bd9Sstevel@tonic-gate uu_avl_pool_t *uu_avl_pool_create(const char *, size_t, size_t,
3327c478bd9Sstevel@tonic-gate     uu_compare_fn_t *, uint32_t);
3337c478bd9Sstevel@tonic-gate #define	UU_AVL_POOL_DEBUG	0x00000001
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate void uu_avl_pool_destroy(uu_avl_pool_t *);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * usage:
3397c478bd9Sstevel@tonic-gate  *
3407c478bd9Sstevel@tonic-gate  *	foo_t *a;
3417c478bd9Sstevel@tonic-gate  *	a = malloc(sizeof(*a));
3427c478bd9Sstevel@tonic-gate  *	uu_avl_node_init(a, &a->foo_avl, pool);
3437c478bd9Sstevel@tonic-gate  *	...
3447c478bd9Sstevel@tonic-gate  *	uu_avl_node_fini(a, &a->foo_avl, pool);
3457c478bd9Sstevel@tonic-gate  *	free(a);
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate void uu_avl_node_init(void *, uu_avl_node_t *, uu_avl_pool_t *);
3487c478bd9Sstevel@tonic-gate void uu_avl_node_fini(void *, uu_avl_node_t *, uu_avl_pool_t *);
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate uu_avl_t *uu_avl_create(uu_avl_pool_t *, void *_parent, uint32_t);
3517c478bd9Sstevel@tonic-gate #define	UU_AVL_DEBUG	0x00000001
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate void uu_avl_destroy(uu_avl_t *);	/* list must be empty */
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate size_t uu_avl_numnodes(uu_avl_t *);
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate void *uu_avl_first(uu_avl_t *);
3587c478bd9Sstevel@tonic-gate void *uu_avl_last(uu_avl_t *);
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate void *uu_avl_next(uu_avl_t *, void *);
3617c478bd9Sstevel@tonic-gate void *uu_avl_prev(uu_avl_t *, void *);
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate int uu_avl_walk(uu_avl_t *, uu_walk_fn_t *, void *, uint32_t);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate uu_avl_walk_t *uu_avl_walk_start(uu_avl_t *, uint32_t);
3667c478bd9Sstevel@tonic-gate void *uu_avl_walk_next(uu_avl_walk_t *);
3677c478bd9Sstevel@tonic-gate void uu_avl_walk_end(uu_avl_walk_t *);
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate void *uu_avl_find(uu_avl_t *, void *, void *, uu_avl_index_t *);
3707c478bd9Sstevel@tonic-gate void uu_avl_insert(uu_avl_t *, void *, uu_avl_index_t);
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate void *uu_avl_nearest_next(uu_avl_t *, uu_avl_index_t);
3737c478bd9Sstevel@tonic-gate void *uu_avl_nearest_prev(uu_avl_t *, uu_avl_index_t);
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate void *uu_avl_teardown(uu_avl_t *, void **);
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate void uu_avl_remove(uu_avl_t *, void *);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate #endif
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate #endif	/* _LIBUUTIL_H */
384