add KRB5_LIB_FUNCTION/KRB5_LIB_CALL to kcm.c
[heimdal.git] / base / heimbase.h
blobd1ca5aa89968e991438c61acea06e2a2fc4f50a1
1 /*
2 * Copyright (c) 2010 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #ifndef HEIM_BASE_H
37 #define HEIM_BASE_H 1
39 #include <sys/types.h>
40 #include <krb5-types.h>
41 #include <stdarg.h>
42 #include <stdbool.h>
44 typedef void * heim_object_t;
45 typedef unsigned int heim_tid_t;
46 typedef heim_object_t heim_bool_t;
47 typedef heim_object_t heim_null_t;
48 #define HEIM_BASE_ONCE_INIT 0
49 typedef long heim_base_once_t; /* XXX arch dependant */
51 void * heim_retain(heim_object_t);
52 void heim_release(heim_object_t);
54 typedef void (*heim_type_dealloc)(void *);
56 void *
57 heim_alloc(size_t size, const char *name, heim_type_dealloc dealloc);
59 heim_tid_t
60 heim_get_tid(heim_object_t object);
62 int
63 heim_cmp(heim_object_t a, heim_object_t b);
65 unsigned long
66 heim_get_hash(heim_object_t ptr);
68 void
69 heim_base_once_f(heim_base_once_t *, void *, void (*)(void *));
71 void
72 heim_abort(const char *fmt, ...)
73 HEIMDAL_NORETURN_ATTRIBUTE
74 HEIMDAL_PRINTF_ATTRIBUTE((printf, 1, 2));
76 void
77 heim_abortv(const char *fmt, va_list ap)
78 HEIMDAL_NORETURN_ATTRIBUTE
79 HEIMDAL_PRINTF_ATTRIBUTE((printf, 1, 0));
81 #define heim_assert(e,t) \
82 (__builtin_expect(!(e), 0) ? heim_abort(t ":" #e) : (void)0)
88 heim_null_t
89 heim_null_create(void);
91 heim_bool_t
92 heim_bool_create(int);
94 int
95 heim_bool_val(heim_bool_t);
98 * Array
101 typedef struct heim_array_data *heim_array_t;
103 heim_array_t heim_array_create(void);
104 heim_tid_t heim_array_get_type_id(void);
106 typedef void (*heim_array_iterator_f_t)(heim_object_t, void *);
108 int heim_array_append_value(heim_array_t, heim_object_t);
109 void heim_array_iterate_f(heim_array_t, heim_array_iterator_f_t, void *);
110 #ifdef __BLOCKS__
111 void heim_array_iterate(heim_array_t, void (^)(heim_object_t));
112 #endif
113 size_t heim_array_get_length(heim_array_t);
114 heim_object_t
115 heim_array_copy_value(heim_array_t, size_t);
116 void heim_array_delete_value(heim_array_t, size_t);
117 #ifdef __BLOCKS__
118 void heim_array_filter(heim_array_t, bool (^)(heim_object_t));
119 #endif
122 * Dict
125 typedef struct heim_dict_data *heim_dict_t;
127 heim_dict_t heim_dict_create(size_t size);
128 heim_tid_t heim_dict_get_type_id(void);
130 typedef void (*heim_dict_iterator_f_t)(heim_object_t, heim_object_t, void *);
132 int heim_dict_add_value(heim_dict_t, heim_object_t, heim_object_t);
133 void heim_dict_iterate_f(heim_dict_t, heim_dict_iterator_f_t, void *);
134 #ifdef __BLOCKS__
135 void heim_dict_iterate(heim_dict_t, void (^)(heim_object_t, heim_object_t));
136 #endif
138 heim_object_t
139 heim_dict_copy_value(heim_dict_t, heim_object_t);
140 void heim_dict_delete_key(heim_dict_t, heim_object_t);
143 * String
146 typedef struct heim_string_data *heim_string_t;
148 heim_string_t heim_string_create(const char *);
149 heim_tid_t heim_string_get_type_id(void);
150 const char * heim_string_get_utf8(heim_string_t);
153 * Number
156 typedef struct heim_number_data *heim_number_t;
158 heim_number_t heim_number_create(int);
159 heim_tid_t heim_number_get_type_id(void);
160 int heim_number_get_int(heim_number_t);
166 typedef struct heim_auto_release * heim_auto_release_t;
168 heim_auto_release_t heim_auto_release_create(void);
169 void heim_auto_release_drain(heim_auto_release_t);
170 void heim_auto_release(heim_object_t);
172 #endif /* HEIM_BASE_H */