1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _LIBUUTIL_H 28*7c478bd9Sstevel@tonic-gate #define _LIBUUTIL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 36*7c478bd9Sstevel@tonic-gate extern "C" { 37*7c478bd9Sstevel@tonic-gate #endif 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* 40*7c478bd9Sstevel@tonic-gate * Standard flags codes. 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate #define UU_DEFAULT 0 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* 45*7c478bd9Sstevel@tonic-gate * Standard error codes. 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate #define UU_ERROR_NONE 0 /* no error */ 48*7c478bd9Sstevel@tonic-gate #define UU_ERROR_INVALID_ARGUMENT 1 /* invalid argument */ 49*7c478bd9Sstevel@tonic-gate #define UU_ERROR_UNKNOWN_FLAG 2 /* passed flag invalid */ 50*7c478bd9Sstevel@tonic-gate #define UU_ERROR_NO_MEMORY 3 /* out of memory */ 51*7c478bd9Sstevel@tonic-gate #define UU_ERROR_CALLBACK_FAILED 4 /* callback-initiated error */ 52*7c478bd9Sstevel@tonic-gate #define UU_ERROR_NOT_SUPPORTED 5 /* operation not supported */ 53*7c478bd9Sstevel@tonic-gate #define UU_ERROR_EMPTY 6 /* no value provided */ 54*7c478bd9Sstevel@tonic-gate #define UU_ERROR_UNDERFLOW 7 /* value is too small */ 55*7c478bd9Sstevel@tonic-gate #define UU_ERROR_OVERFLOW 8 /* value is too value */ 56*7c478bd9Sstevel@tonic-gate #define UU_ERROR_INVALID_CHAR 9 /* value contains unexpected char */ 57*7c478bd9Sstevel@tonic-gate #define UU_ERROR_INVALID_DIGIT 10 /* value contains digit not in base */ 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #define UU_ERROR_SYSTEM 99 /* underlying system error */ 60*7c478bd9Sstevel@tonic-gate #define UU_ERROR_UNKNOWN 100 /* error status not known */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * Standard program exit codes. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate #define UU_EXIT_OK (*(uu_exit_ok())) 66*7c478bd9Sstevel@tonic-gate #define UU_EXIT_FATAL (*(uu_exit_fatal())) 67*7c478bd9Sstevel@tonic-gate #define UU_EXIT_USAGE (*(uu_exit_usage())) 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate /* 70*7c478bd9Sstevel@tonic-gate * Exit status profiles. 71*7c478bd9Sstevel@tonic-gate */ 72*7c478bd9Sstevel@tonic-gate #define UU_PROFILE_DEFAULT 0 73*7c478bd9Sstevel@tonic-gate #define UU_PROFILE_LAUNCHER 1 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate /* 76*7c478bd9Sstevel@tonic-gate * Error reporting functions. 77*7c478bd9Sstevel@tonic-gate */ 78*7c478bd9Sstevel@tonic-gate uint32_t uu_error(void); 79*7c478bd9Sstevel@tonic-gate const char *uu_strerror(uint32_t); 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * Program notification functions. 83*7c478bd9Sstevel@tonic-gate */ 84*7c478bd9Sstevel@tonic-gate extern void uu_alt_exit(int); 85*7c478bd9Sstevel@tonic-gate extern const char *uu_setpname(char *); 86*7c478bd9Sstevel@tonic-gate extern const char *uu_getpname(void); 87*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 88*7c478bd9Sstevel@tonic-gate extern void uu_warn(const char *, ...); 89*7c478bd9Sstevel@tonic-gate extern void uu_vwarn(const char *, va_list); 90*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 91*7c478bd9Sstevel@tonic-gate extern void uu_die(const char *, ...); 92*7c478bd9Sstevel@tonic-gate extern void uu_vdie(const char *, va_list); 93*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/ 94*7c478bd9Sstevel@tonic-gate extern void uu_xdie(int, const char *, ...); 95*7c478bd9Sstevel@tonic-gate extern void uu_vxdie(int, const char *, va_list); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * Exit status functions (not to be used directly) 99*7c478bd9Sstevel@tonic-gate */ 100*7c478bd9Sstevel@tonic-gate extern int *uu_exit_ok(void); 101*7c478bd9Sstevel@tonic-gate extern int *uu_exit_fatal(void); 102*7c478bd9Sstevel@tonic-gate extern int *uu_exit_usage(void); 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* 105*7c478bd9Sstevel@tonic-gate * string->number conversions 106*7c478bd9Sstevel@tonic-gate */ 107*7c478bd9Sstevel@tonic-gate extern int uu_strtoint(const char *, void *, size_t, int, int64_t, int64_t); 108*7c478bd9Sstevel@tonic-gate extern int uu_strtouint(const char *, void *, size_t, int, uint64_t, uint64_t); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* 111*7c478bd9Sstevel@tonic-gate * Debug print facility functions. 112*7c478bd9Sstevel@tonic-gate */ 113*7c478bd9Sstevel@tonic-gate typedef struct uu_dprintf uu_dprintf_t; 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate typedef enum { 116*7c478bd9Sstevel@tonic-gate UU_DPRINTF_SILENT, 117*7c478bd9Sstevel@tonic-gate UU_DPRINTF_FATAL, 118*7c478bd9Sstevel@tonic-gate UU_DPRINTF_WARNING, 119*7c478bd9Sstevel@tonic-gate UU_DPRINTF_NOTICE, 120*7c478bd9Sstevel@tonic-gate UU_DPRINTF_INFO, 121*7c478bd9Sstevel@tonic-gate UU_DPRINTF_DEBUG 122*7c478bd9Sstevel@tonic-gate } uu_dprintf_severity_t; 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate extern uu_dprintf_t *uu_dprintf_create(const char *, uu_dprintf_severity_t, 125*7c478bd9Sstevel@tonic-gate uint_t); 126*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/ 127*7c478bd9Sstevel@tonic-gate extern void uu_dprintf(uu_dprintf_t *, uu_dprintf_severity_t, 128*7c478bd9Sstevel@tonic-gate const char *, ...); 129*7c478bd9Sstevel@tonic-gate extern void uu_dprintf_destroy(uu_dprintf_t *); 130*7c478bd9Sstevel@tonic-gate extern const char *uu_dprintf_getname(uu_dprintf_t *); 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate /* 133*7c478bd9Sstevel@tonic-gate * Identifier test flags and function. 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate #define UU_NAME_DOMAIN 0x1 /* allow SUNW, or com.sun, prefix */ 136*7c478bd9Sstevel@tonic-gate #define UU_NAME_PATH 0x2 /* allow '/'-delimited paths */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate int uu_check_name(const char *, uint_t); 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate /* 141*7c478bd9Sstevel@tonic-gate * File creation functions. 142*7c478bd9Sstevel@tonic-gate */ 143*7c478bd9Sstevel@tonic-gate extern int uu_open_tmp(const char *dir, uint_t uflags); 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * Convenience functions. 147*7c478bd9Sstevel@tonic-gate */ 148*7c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 149*7c478bd9Sstevel@tonic-gate extern char *uu_msprintf(const char *format, ...); 150*7c478bd9Sstevel@tonic-gate extern void *uu_zalloc(size_t); 151*7c478bd9Sstevel@tonic-gate extern void uu_free(void *); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* 154*7c478bd9Sstevel@tonic-gate * Comparison function type definition. 155*7c478bd9Sstevel@tonic-gate * Developers should be careful in their use of the _private argument. If you 156*7c478bd9Sstevel@tonic-gate * break interface guarantees, you get undefined behavior. 157*7c478bd9Sstevel@tonic-gate */ 158*7c478bd9Sstevel@tonic-gate typedef int uu_compare_fn_t(const void *__left, const void *__right, 159*7c478bd9Sstevel@tonic-gate void *__private); 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate /* 162*7c478bd9Sstevel@tonic-gate * Walk variant flags. 163*7c478bd9Sstevel@tonic-gate * A data structure need not provide support for all variants and 164*7c478bd9Sstevel@tonic-gate * combinations. Refer to the appropriate documentation. 165*7c478bd9Sstevel@tonic-gate */ 166*7c478bd9Sstevel@tonic-gate #define UU_WALK_ROBUST 0x00000001 /* walk can survive removes */ 167*7c478bd9Sstevel@tonic-gate #define UU_WALK_REVERSE 0x00000002 /* reverse walk order */ 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #define UU_WALK_PREORDER 0x00000010 /* walk tree in pre-order */ 170*7c478bd9Sstevel@tonic-gate #define UU_WALK_POSTORDER 0x00000020 /* walk tree in post-order */ 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate /* 173*7c478bd9Sstevel@tonic-gate * Walk callback function return codes. 174*7c478bd9Sstevel@tonic-gate */ 175*7c478bd9Sstevel@tonic-gate #define UU_WALK_ERROR -1 176*7c478bd9Sstevel@tonic-gate #define UU_WALK_NEXT 0 177*7c478bd9Sstevel@tonic-gate #define UU_WALK_DONE 1 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * Walk callback function type definition. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate typedef int uu_walk_fn_t(void *_elem, void *_private); 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /* 185*7c478bd9Sstevel@tonic-gate * lists: opaque structures 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate typedef struct uu_list_pool uu_list_pool_t; 188*7c478bd9Sstevel@tonic-gate typedef struct uu_list uu_list_t; 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate typedef struct uu_list_node { 191*7c478bd9Sstevel@tonic-gate uintptr_t uln_opaque[2]; 192*7c478bd9Sstevel@tonic-gate } uu_list_node_t; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate typedef struct uu_list_walk uu_list_walk_t; 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate typedef uintptr_t uu_list_index_t; 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* 199*7c478bd9Sstevel@tonic-gate * lists: interface 200*7c478bd9Sstevel@tonic-gate * 201*7c478bd9Sstevel@tonic-gate * basic usage: 202*7c478bd9Sstevel@tonic-gate * typedef struct foo { 203*7c478bd9Sstevel@tonic-gate * ... 204*7c478bd9Sstevel@tonic-gate * uu_list_node_t foo_node; 205*7c478bd9Sstevel@tonic-gate * ... 206*7c478bd9Sstevel@tonic-gate * } foo_t; 207*7c478bd9Sstevel@tonic-gate * 208*7c478bd9Sstevel@tonic-gate * static int 209*7c478bd9Sstevel@tonic-gate * foo_compare(void *l_arg, void *r_arg, void *private) 210*7c478bd9Sstevel@tonic-gate * { 211*7c478bd9Sstevel@tonic-gate * foo_t *l = l_arg; 212*7c478bd9Sstevel@tonic-gate * foo_t *r = r_arg; 213*7c478bd9Sstevel@tonic-gate * 214*7c478bd9Sstevel@tonic-gate * if (... l greater than r ...) 215*7c478bd9Sstevel@tonic-gate * return (1); 216*7c478bd9Sstevel@tonic-gate * if (... l less than r ...) 217*7c478bd9Sstevel@tonic-gate * return (-1); 218*7c478bd9Sstevel@tonic-gate * return (0); 219*7c478bd9Sstevel@tonic-gate * } 220*7c478bd9Sstevel@tonic-gate * 221*7c478bd9Sstevel@tonic-gate * ... 222*7c478bd9Sstevel@tonic-gate * // at initialization time 223*7c478bd9Sstevel@tonic-gate * foo_pool = uu_list_pool_create("foo_pool", 224*7c478bd9Sstevel@tonic-gate * sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare, 225*7c478bd9Sstevel@tonic-gate * debugging? 0 : UU_AVL_POOL_DEBUG); 226*7c478bd9Sstevel@tonic-gate * ... 227*7c478bd9Sstevel@tonic-gate */ 228*7c478bd9Sstevel@tonic-gate uu_list_pool_t *uu_list_pool_create(const char *, size_t, size_t, 229*7c478bd9Sstevel@tonic-gate uu_compare_fn_t *, uint32_t); 230*7c478bd9Sstevel@tonic-gate #define UU_LIST_POOL_DEBUG 0x00000001 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate void uu_list_pool_destroy(uu_list_pool_t *); 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate /* 235*7c478bd9Sstevel@tonic-gate * usage: 236*7c478bd9Sstevel@tonic-gate * 237*7c478bd9Sstevel@tonic-gate * foo_t *a; 238*7c478bd9Sstevel@tonic-gate * a = malloc(sizeof(*a)); 239*7c478bd9Sstevel@tonic-gate * uu_list_node_init(a, &a->foo_list, pool); 240*7c478bd9Sstevel@tonic-gate * ... 241*7c478bd9Sstevel@tonic-gate * uu_list_node_fini(a, &a->foo_list, pool); 242*7c478bd9Sstevel@tonic-gate * free(a); 243*7c478bd9Sstevel@tonic-gate */ 244*7c478bd9Sstevel@tonic-gate void uu_list_node_init(void *, uu_list_node_t *, uu_list_pool_t *); 245*7c478bd9Sstevel@tonic-gate void uu_list_node_fini(void *, uu_list_node_t *, uu_list_pool_t *); 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate uu_list_t *uu_list_create(uu_list_pool_t *, void *_parent, uint32_t); 248*7c478bd9Sstevel@tonic-gate #define UU_LIST_DEBUG 0x00000001 249*7c478bd9Sstevel@tonic-gate #define UU_LIST_SORTED 0x00000002 /* list is sorted */ 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate void uu_list_destroy(uu_list_t *); /* list must be empty */ 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate size_t uu_list_numnodes(uu_list_t *); 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate void *uu_list_first(uu_list_t *); 256*7c478bd9Sstevel@tonic-gate void *uu_list_last(uu_list_t *); 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate void *uu_list_next(uu_list_t *, void *); 259*7c478bd9Sstevel@tonic-gate void *uu_list_prev(uu_list_t *, void *); 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate int uu_list_walk(uu_list_t *, uu_walk_fn_t *, void *, uint32_t); 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate uu_list_walk_t *uu_list_walk_start(uu_list_t *, uint32_t); 264*7c478bd9Sstevel@tonic-gate void *uu_list_walk_next(uu_list_walk_t *); 265*7c478bd9Sstevel@tonic-gate void uu_list_walk_end(uu_list_walk_t *); 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate void *uu_list_find(uu_list_t *, void *, void *, uu_list_index_t *); 268*7c478bd9Sstevel@tonic-gate void uu_list_insert(uu_list_t *, void *, uu_list_index_t); 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate void *uu_list_nearest_next(uu_list_t *, uu_list_index_t); 271*7c478bd9Sstevel@tonic-gate void *uu_list_nearest_prev(uu_list_t *, uu_list_index_t); 272*7c478bd9Sstevel@tonic-gate 273*7c478bd9Sstevel@tonic-gate void *uu_list_teardown(uu_list_t *, void **); 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate void uu_list_remove(uu_list_t *, void *); 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate /* 278*7c478bd9Sstevel@tonic-gate * lists: interfaces for non-sorted lists only 279*7c478bd9Sstevel@tonic-gate */ 280*7c478bd9Sstevel@tonic-gate int uu_list_insert_before(uu_list_t *, void *_target, void *_elem); 281*7c478bd9Sstevel@tonic-gate int uu_list_insert_after(uu_list_t *, void *_target, void *_elem); 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate /* 284*7c478bd9Sstevel@tonic-gate * avl trees: opaque structures 285*7c478bd9Sstevel@tonic-gate */ 286*7c478bd9Sstevel@tonic-gate typedef struct uu_avl_pool uu_avl_pool_t; 287*7c478bd9Sstevel@tonic-gate typedef struct uu_avl uu_avl_t; 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate typedef struct uu_avl_node { 290*7c478bd9Sstevel@tonic-gate #ifdef _LP64 291*7c478bd9Sstevel@tonic-gate uintptr_t uan_opaque[3]; 292*7c478bd9Sstevel@tonic-gate #else 293*7c478bd9Sstevel@tonic-gate uintptr_t uan_opaque[4]; 294*7c478bd9Sstevel@tonic-gate #endif 295*7c478bd9Sstevel@tonic-gate } uu_avl_node_t; 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate typedef struct uu_avl_walk uu_avl_walk_t; 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate typedef uintptr_t uu_avl_index_t; 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate /* 302*7c478bd9Sstevel@tonic-gate * avl trees: interface 303*7c478bd9Sstevel@tonic-gate * 304*7c478bd9Sstevel@tonic-gate * basic usage: 305*7c478bd9Sstevel@tonic-gate * typedef struct foo { 306*7c478bd9Sstevel@tonic-gate * ... 307*7c478bd9Sstevel@tonic-gate * uu_avl_node_t foo_node; 308*7c478bd9Sstevel@tonic-gate * ... 309*7c478bd9Sstevel@tonic-gate * } foo_t; 310*7c478bd9Sstevel@tonic-gate * 311*7c478bd9Sstevel@tonic-gate * static int 312*7c478bd9Sstevel@tonic-gate * foo_compare(void *l_arg, void *r_arg, void *private) 313*7c478bd9Sstevel@tonic-gate * { 314*7c478bd9Sstevel@tonic-gate * foo_t *l = l_arg; 315*7c478bd9Sstevel@tonic-gate * foo_t *r = r_arg; 316*7c478bd9Sstevel@tonic-gate * 317*7c478bd9Sstevel@tonic-gate * if (... l greater than r ...) 318*7c478bd9Sstevel@tonic-gate * return (1); 319*7c478bd9Sstevel@tonic-gate * if (... l less than r ...) 320*7c478bd9Sstevel@tonic-gate * return (-1); 321*7c478bd9Sstevel@tonic-gate * return (0); 322*7c478bd9Sstevel@tonic-gate * } 323*7c478bd9Sstevel@tonic-gate * 324*7c478bd9Sstevel@tonic-gate * ... 325*7c478bd9Sstevel@tonic-gate * // at initialization time 326*7c478bd9Sstevel@tonic-gate * foo_pool = uu_avl_pool_create("foo_pool", 327*7c478bd9Sstevel@tonic-gate * sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare, 328*7c478bd9Sstevel@tonic-gate * debugging? 0 : UU_AVL_POOL_DEBUG); 329*7c478bd9Sstevel@tonic-gate * ... 330*7c478bd9Sstevel@tonic-gate */ 331*7c478bd9Sstevel@tonic-gate uu_avl_pool_t *uu_avl_pool_create(const char *, size_t, size_t, 332*7c478bd9Sstevel@tonic-gate uu_compare_fn_t *, uint32_t); 333*7c478bd9Sstevel@tonic-gate #define UU_AVL_POOL_DEBUG 0x00000001 334*7c478bd9Sstevel@tonic-gate 335*7c478bd9Sstevel@tonic-gate void uu_avl_pool_destroy(uu_avl_pool_t *); 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate /* 338*7c478bd9Sstevel@tonic-gate * usage: 339*7c478bd9Sstevel@tonic-gate * 340*7c478bd9Sstevel@tonic-gate * foo_t *a; 341*7c478bd9Sstevel@tonic-gate * a = malloc(sizeof(*a)); 342*7c478bd9Sstevel@tonic-gate * uu_avl_node_init(a, &a->foo_avl, pool); 343*7c478bd9Sstevel@tonic-gate * ... 344*7c478bd9Sstevel@tonic-gate * uu_avl_node_fini(a, &a->foo_avl, pool); 345*7c478bd9Sstevel@tonic-gate * free(a); 346*7c478bd9Sstevel@tonic-gate */ 347*7c478bd9Sstevel@tonic-gate void uu_avl_node_init(void *, uu_avl_node_t *, uu_avl_pool_t *); 348*7c478bd9Sstevel@tonic-gate void uu_avl_node_fini(void *, uu_avl_node_t *, uu_avl_pool_t *); 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate uu_avl_t *uu_avl_create(uu_avl_pool_t *, void *_parent, uint32_t); 351*7c478bd9Sstevel@tonic-gate #define UU_AVL_DEBUG 0x00000001 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate void uu_avl_destroy(uu_avl_t *); /* list must be empty */ 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate size_t uu_avl_numnodes(uu_avl_t *); 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate void *uu_avl_first(uu_avl_t *); 358*7c478bd9Sstevel@tonic-gate void *uu_avl_last(uu_avl_t *); 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate void *uu_avl_next(uu_avl_t *, void *); 361*7c478bd9Sstevel@tonic-gate void *uu_avl_prev(uu_avl_t *, void *); 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate int uu_avl_walk(uu_avl_t *, uu_walk_fn_t *, void *, uint32_t); 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate uu_avl_walk_t *uu_avl_walk_start(uu_avl_t *, uint32_t); 366*7c478bd9Sstevel@tonic-gate void *uu_avl_walk_next(uu_avl_walk_t *); 367*7c478bd9Sstevel@tonic-gate void uu_avl_walk_end(uu_avl_walk_t *); 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate void *uu_avl_find(uu_avl_t *, void *, void *, uu_avl_index_t *); 370*7c478bd9Sstevel@tonic-gate void uu_avl_insert(uu_avl_t *, void *, uu_avl_index_t); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate void *uu_avl_nearest_next(uu_avl_t *, uu_avl_index_t); 373*7c478bd9Sstevel@tonic-gate void *uu_avl_nearest_prev(uu_avl_t *, uu_avl_index_t); 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate void *uu_avl_teardown(uu_avl_t *, void **); 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate void uu_avl_remove(uu_avl_t *, void *); 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate #endif 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate #endif /* _LIBUUTIL_H */ 384