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