Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../../usr/include/libuutil.h
Real path: /usr/include/libuutil.h
Zurück
/* * Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved. */ #ifndef _LIBUUTIL_H #define _LIBUUTIL_H #include <sys/avl.h> #include <sys/types.h> #include <stdarg.h> #include <stdio.h> #include <fcntl.h> #ifdef __cplusplus extern "C" { #endif /* * INTERFACES DEFINED IN THIS FILE DO NOT CONSTITUTE A PUBLIC INTERFACE. * * Do not consume these interfaces; your program will break in the future * (even in a patch) if you do. */ /* * Standard flags codes. */ #define UU_DEFAULT 0 /* * Standard error codes. */ #define UU_ERROR_NONE 0 /* no error */ #define UU_ERROR_INVALID_ARGUMENT 1 /* invalid argument */ #define UU_ERROR_UNKNOWN_FLAG 2 /* passed flag invalid */ #define UU_ERROR_NO_MEMORY 3 /* out of memory */ #define UU_ERROR_CALLBACK_FAILED 4 /* callback-initiated error */ #define UU_ERROR_NOT_SUPPORTED 5 /* operation not supported */ #define UU_ERROR_EMPTY 6 /* no value provided */ #define UU_ERROR_UNDERFLOW 7 /* value is too small */ #define UU_ERROR_OVERFLOW 8 /* value is too value */ #define UU_ERROR_INVALID_CHAR 9 /* value contains unexpected char */ #define UU_ERROR_INVALID_DIGIT 10 /* value contains digit not in base */ #define UU_ERROR_SYSTEM 99 /* underlying system error */ #define UU_ERROR_UNKNOWN 100 /* error status not known */ /* * Standard program exit codes. */ #define UU_EXIT_OK (*(uu_exit_ok())) #define UU_EXIT_FATAL (*(uu_exit_fatal())) #define UU_EXIT_USAGE (*(uu_exit_usage())) /* * Exit status profiles. */ #define UU_PROFILE_DEFAULT 0 #define UU_PROFILE_LAUNCHER 1 /* * Error reporting functions. */ uint32_t uu_error(void); const char *uu_strerror(uint32_t); /* * Program notification functions. */ extern void uu_alt_exit(int); extern const char *uu_setpname(char *); extern const char *uu_getpname(void); /*PRINTFLIKE1*/ extern void uu_warn(const char *, ...); extern void uu_vwarn(const char *, va_list); /*PRINTFLIKE1*/ extern void uu_die(const char *, ...) __NORETURN; extern void uu_vdie(const char *, va_list) __NORETURN; /*PRINTFLIKE2*/ extern void uu_xdie(int, const char *, ...) __NORETURN; extern void uu_vxdie(int, const char *, va_list) __NORETURN; /* * Exit status functions (not to be used directly) */ extern int *uu_exit_ok(void); extern int *uu_exit_fatal(void); extern int *uu_exit_usage(void); /* * string->number conversions */ extern int uu_strtoint(const char *, void *, size_t, int, int64_t, int64_t); extern int uu_strtouint(const char *, void *, size_t, int, uint64_t, uint64_t); extern long long uu_strtonum(const char *, long long, long long, const char **); #ifdef OBSD_COMP /* * Alias will be defined when source code is being compiled with OpenBSD * compatibility mode flag turned on (-DOBSD_COMP). */ #define strtonum(_str_, _min_, _max_, _estr_) \ uu_strtonum((_str_), (_min_), (_max_), (_estr_)) #endif /* OBSD_COMP */ /* * Debug print facility functions. */ typedef struct uu_dprintf uu_dprintf_t; typedef enum { UU_DPRINTF_SILENT, UU_DPRINTF_FATAL, UU_DPRINTF_WARNING, UU_DPRINTF_NOTICE, UU_DPRINTF_INFO, UU_DPRINTF_DEBUG } uu_dprintf_severity_t; extern uu_dprintf_t *uu_dprintf_create(const char *, uu_dprintf_severity_t, uint_t); /*PRINTFLIKE3*/ extern void uu_dprintf(uu_dprintf_t *, uu_dprintf_severity_t, const char *, ...); extern void uu_dprintf_destroy(uu_dprintf_t *); extern const char *uu_dprintf_getname(uu_dprintf_t *); /* * Identifier test flags and function. * * UU_NAME_DOMAIN : * allow stock tiker and domain prefix: e.g. SUNW, or com.sun, * UU_NAME_PATH : * allow '/'-delimited paths * UU_NAME_URI * allow RFC 3986 compliant names * UU_NAME_SVCINST * allow names starting with alphanumeric characters. Dot '.', * undescore '_', and hyphen '-' are also allowed after the 1st * character. Stock ticker and domain prefix, such as SUNW, and com.sun, * also allowed. */ #define UU_NAME_DOMAIN 0x1 #define UU_NAME_PATH 0x2 #define UU_NAME_URI 0x4 #define UU_NAME_SVCINST 0X8 int uu_check_name(const char *, uint_t); /* * File creation functions. */ extern int uu_open_tmp(const char *dir, uint_t uflags); /*PRINTFLIKE1*/ extern char *uu_msprintf(const char *format, ...); extern void *uu_alloc(size_t); extern void *uu_calloc(size_t, size_t); extern void *uu_zalloc(size_t); extern void *uu_realloc(void *ptr, size_t size); extern char *uu_strdup(const char *); extern void uu_free(void *); extern boolean_t uu_strcaseeq(const char *a, const char *b); extern boolean_t uu_streq(const char *a, const char *b); extern char *uu_strndup(const char *s, size_t n); extern boolean_t uu_strbw(const char *a, const char *b); extern void *uu_memdup(const void *buf, size_t sz); extern void uu_dump(FILE *out, const char *prefix, const void *buf, size_t len); /* * Comparison function type definition. * Developers should be careful in their use of the _private argument. If you * break interface guarantees, you get undefined behavior. */ typedef int uu_compare_fn_t(const void *__left, const void *__right, void *__private); /* * Walk variant flags. * A data structure need not provide support for all variants and * combinations. Refer to the appropriate documentation. */ #define UU_WALK_ROBUST 0x00000001 /* walk can survive removes */ #define UU_WALK_REVERSE 0x00000002 /* reverse walk order */ #define UU_WALK_PREORDER 0x00000010 /* walk tree in pre-order */ #define UU_WALK_POSTORDER 0x00000020 /* walk tree in post-order */ /* * Walk callback function return codes. */ #define UU_WALK_ERROR -1 #define UU_WALK_NEXT 0 #define UU_WALK_DONE 1 /* * Walk callback function type definition. */ typedef int uu_walk_fn_t(void *_elem, void *_private); /* * lists: opaque structures */ typedef struct uu_list_pool uu_list_pool_t; typedef struct uu_list uu_list_t; typedef struct uu_list_node { uintptr_t uln_opaque[2]; } uu_list_node_t; typedef struct uu_list_walk uu_list_walk_t; typedef uintptr_t uu_list_index_t; /* * lists: interface * * basic usage: * typedef struct foo { * ... * uu_list_node_t foo_node; * ... * } foo_t; * * static int * foo_compare(const void *l_arg, const void *r_arg, void *private) * { * foo_t *l = l_arg; * foo_t *r = r_arg; * * if (... l greater than r ...) * return (1); * if (... l less than r ...) * return (-1); * return (0); * } * * ... * // at initialization time * foo_pool = uu_list_pool_create("foo_pool", * sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare, * debugging ? UU_LIST_POOL_DEBUG : 0); * ... */ uu_list_pool_t *uu_list_pool_create(const char *, size_t, size_t, uu_compare_fn_t *, uint32_t); #define UU_LIST_POOL_DEBUG 0x00000001 void uu_list_pool_destroy(uu_list_pool_t *); /* * usage: * * foo_t *a; * a = malloc(sizeof(*a)); * uu_list_node_init(a, &a->foo_list, pool); * ... * uu_list_node_fini(a, &a->foo_list, pool); * free(a); */ void uu_list_node_init(void *, uu_list_node_t *, uu_list_pool_t *); void uu_list_node_fini(void *, uu_list_node_t *, uu_list_pool_t *); uu_list_t *uu_list_create(uu_list_pool_t *, void *_parent, uint32_t); #define UU_LIST_DEBUG 0x00000001 #define UU_LIST_SORTED 0x00000002 /* list is sorted */ void uu_list_destroy(uu_list_t *); /* list must be empty */ size_t uu_list_numnodes(uu_list_t *); void *uu_list_first(uu_list_t *); void *uu_list_last(uu_list_t *); void *uu_list_next(uu_list_t *, void *); void *uu_list_prev(uu_list_t *, void *); int uu_list_walk(uu_list_t *, uu_walk_fn_t *, void *, uint32_t); uu_list_walk_t *uu_list_walk_start(uu_list_t *, uint32_t); void *uu_list_walk_next(uu_list_walk_t *); void uu_list_walk_end(uu_list_walk_t *); void *uu_list_find(uu_list_t *, void *, void *, uu_list_index_t *); void uu_list_insert(uu_list_t *, void *, uu_list_index_t); void *uu_list_nearest_next(uu_list_t *, uu_list_index_t); void *uu_list_nearest_prev(uu_list_t *, uu_list_index_t); void *uu_list_teardown(uu_list_t *, void **); void uu_list_remove(uu_list_t *, void *); /* * lists: interfaces for non-sorted lists only */ int uu_list_insert_before(uu_list_t *, void *_target, void *_elem); int uu_list_insert_after(uu_list_t *, void *_target, void *_elem); /* * avl trees: opaque structures */ typedef struct uu_avl_pool uu_avl_pool_t; typedef struct uu_avl uu_avl_t; typedef struct uu_avl_node { #ifdef _LP64 uintptr_t uan_opaque[3]; #else uintptr_t uan_opaque[4]; #endif } uu_avl_node_t; typedef struct uu_avl_walk uu_avl_walk_t; typedef uintptr_t uu_avl_index_t; /* * avl trees: interface * * basic usage: * typedef struct foo { * ... * uu_avl_node_t foo_node; * ... * } foo_t; * * static int * foo_compare(void *l_arg, void *r_arg, void *private) * { * foo_t *l = l_arg; * foo_t *r = r_arg; * * if (... l greater than r ...) * return (1); * if (... l less than r ...) * return (-1); * return (0); * } * * ... * // at initialization time * foo_pool = uu_avl_pool_create("foo_pool", * sizeof (foo_t), offsetof(foo_t, foo_node), foo_compare, * debugging? 0 : UU_AVL_POOL_DEBUG); * ... */ uu_avl_pool_t *uu_avl_pool_create(const char *, size_t, size_t, uu_compare_fn_t *, uint32_t); #define UU_AVL_POOL_DEBUG 0x00000001 void uu_avl_pool_destroy(uu_avl_pool_t *); /* * usage: * * foo_t *a; * a = malloc(sizeof(*a)); * uu_avl_node_init(a, &a->foo_avl, pool); * ... * uu_avl_node_fini(a, &a->foo_avl, pool); * free(a); */ void uu_avl_node_init(void *, uu_avl_node_t *, uu_avl_pool_t *); void uu_avl_node_fini(void *, uu_avl_node_t *, uu_avl_pool_t *); uu_avl_t *uu_avl_create(uu_avl_pool_t *, void *_parent, uint32_t); #define UU_AVL_DEBUG 0x00000001 void uu_avl_destroy(uu_avl_t *); /* list must be empty */ size_t uu_avl_numnodes(uu_avl_t *); void *uu_avl_first(uu_avl_t *); void *uu_avl_last(uu_avl_t *); void *uu_avl_next(uu_avl_t *, void *); void *uu_avl_prev(uu_avl_t *, void *); int uu_avl_walk(uu_avl_t *, uu_walk_fn_t *, void *, uint32_t); uu_avl_walk_t *uu_avl_walk_start(uu_avl_t *, uint32_t); void *uu_avl_walk_next(uu_avl_walk_t *); void uu_avl_walk_end(uu_avl_walk_t *); void *uu_avl_find(uu_avl_t *, void *, void *, uu_avl_index_t *); void uu_avl_insert(uu_avl_t *, void *, uu_avl_index_t); void *uu_avl_nearest_next(uu_avl_t *, uu_avl_index_t); void *uu_avl_nearest_prev(uu_avl_t *, uu_avl_index_t); void *uu_avl_teardown(uu_avl_t *, void **); void uu_avl_remove(uu_avl_t *, void *); /* Get executable path */ char *uu_get_exec_path_by_pid(pid_t); const char *uu_get_exec_path_self(void); /* * Walk (almost) all of the locks on a file. */ typedef int uu_lockwalk_f(void *, struct flock64 *); int uu_lockwalk(int, uu_lockwalk_f *, void *); ssize_t uu_uri_decode(const char *encoded, char *buf, size_t size, char c, int flags); ssize_t uu_uri_encode(const char *name, char *buf, size_t size, char c, int flags); /* uid/gid cache interfaces visible to other utilities. */ char *uu_uid_cache_lookup(uid_t uid); void uu_uid_cache_free(void); char *uu_gid_cache_lookup(gid_t gid); void uu_gid_cache_free(void); /* FNV1a hashing */ typedef uint64_t uu_fnv1a_64_t; void uu_fnv1a_hash64(const char *, size_t, uu_fnv1a_64_t *); boolean_t uu_fnv1a_hash64_cmp(const uu_fnv1a_64_t *, const uu_fnv1a_64_t *); /* * priority queues: opaque structure */ typedef struct uu_prioq uu_prioq_t; /* * priority queue flag */ typedef enum { UU_PRIOQ_DEBUG = 0x1 } uu_prioq_flag_t; /* * priority queues: interface * * basic usage: * typedef struct foo { * ... * } foo_t; * * ... * * foo_prioq = uu_prioq_create("foo_prioq", parent, * debugging ? 0 : UU_PRIOQ_DEBUG); * * ... * * * a = uu_zalloc(sizeof(foo_t)); * * if (uu_prioq_enqueue(foo_prioq, priority, a) != 0) { * // handle uu_error() * } * * ... * * a = uu_prioq_dequeue(foo_prioq); * * ... * * uu_free(a); * * ... * * uu_prioq_destroy(foo_prioq); */ uu_prioq_t *uu_prioq_create(const char *, void *, uu_prioq_flag_t); void uu_prioq_destroy(uu_prioq_t *); /* priority queue must be empty */ size_t uu_prioq_numnodes(uu_prioq_t *); void *uu_prioq_first(uu_prioq_t *); int uu_prioq_enqueue(uu_prioq_t *, uint64_t, void *); void *uu_prioq_dequeue(uu_prioq_t *); /* * pointer store data structures */ typedef struct uu_ptr_store { avl_tree_t uu_ptr_tree; /* top of tree */ pthread_mutex_t uu_ptr_lock; /* tree lock */ } uu_ptr_store_t; typedef struct uu_ptr_node { avl_node_t uu_ptr_avl_node; /* how we hook into tree */ char *uu_ptr_name; /* name of this node */ void *uu_ptr_value; /* pointer stored here */ } uu_ptr_node_t; /* * pointer store routines */ void uu_ptr_init(uu_ptr_store_t *); uu_ptr_store_t *uu_ptr_create(void); void *uu_ptr_find(uu_ptr_store_t *, const char *); void **uu_ptr_get(uu_ptr_store_t *, const char *); int uu_ptr_walk(uu_ptr_store_t *, int (*)(const char *, void *, void *), void *); void *uu_ptr_free(uu_ptr_store_t *, const char *); void uu_ptr_destroy(uu_ptr_store_t *); #ifdef __cplusplus } #endif #endif /* _LIBUUTIL_H */