This source file includes following definitions.
- g_hash_prepend_value
- g_hash_table_get_values
- g_hash_table_nth_data
- g_hash_table_iter_init
- g_hash_table_iter_next
- g_hash_table_iter_remove
- g_strcmp0
- g_list_free_full
1 #ifndef PORTABILITY_H
2 # define PORTABILITY_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 # define EOS '\0'
25 # define DIMOF(a) ((int) (sizeof(a)/sizeof(a[0])) )
26
27
28
29 # undef _GNU_SOURCE
30 # define _GNU_SOURCE
31
32
33 # ifdef HAVE_CONFIG_H
34 # include <config.h>
35 # endif
36
37
38
39 # ifndef HAVE_DAEMON
40
41 int daemon(int nochdir, int noclose);
42 # endif
43
44 # ifndef HAVE_SETENV
45
46 int setenv(const char *name, const char *value, int why);
47 # endif
48
49 # ifndef HAVE_STRERROR
50
51 char *strerror(int errnum);
52 # endif
53
54 # ifndef HAVE_STRCHRNUL
55
56 char *strchrnul(const char *s, int c_in);
57 # endif
58
59 # ifndef HAVE_ALPHASORT
60 # include <dirent.h>
61 int
62 alphasort(const void *dirent1, const void *dirent2);
63 # endif
64
65 # ifndef HAVE_STRNLEN
66 size_t strnlen(const char *s, size_t maxlen);
67 # else
68 # define USE_GNU
69 # endif
70
71 # ifndef HAVE_STRNDUP
72 char *strndup(const char *str, size_t len);
73 # else
74 # define USE_GNU
75 # endif
76
77 # include <glib.h>
78 # if !GLIB_CHECK_VERSION(2,14,0)
79
80 typedef struct fake_ghi {
81 GHashTable *hash;
82 int nth;
83 int lpc;
84 gpointer key;
85 gpointer value;
86 } GHashTableIter;
87
88 static inline void
89 g_hash_prepend_value(gpointer key, gpointer value, gpointer user_data)
90 {
91 GList **values = (GList **) user_data;
92
93 *values = g_list_prepend(*values, value);
94 }
95
96
97 static inline GList *
98 g_hash_table_get_values(GHashTable * hash_table)
99 {
100 GList *values = NULL;
101
102 g_hash_table_foreach(hash_table, g_hash_prepend_value, &values);
103 return values;
104 }
105 # endif
106
107 # if !GLIB_CHECK_VERSION(2,16,0)
108
109 static inline gboolean
110 g_hash_table_nth_data(gpointer key, gpointer value, gpointer user_data)
111 {
112 GHashTableIter *iter = (GHashTableIter *) user_data;
113
114 if (iter->lpc++ == iter->nth) {
115 iter->key = key;
116 iter->value = value;
117 return TRUE;
118 }
119 return FALSE;
120 }
121
122 static inline void
123 g_hash_table_iter_init(GHashTableIter * iter, GHashTable * hash_table)
124 {
125 iter->hash = hash_table;
126 iter->nth = 0;
127 iter->lpc = 0;
128 iter->key = NULL;
129 iter->value = NULL;
130 }
131
132 static inline gboolean
133 g_hash_table_iter_next(GHashTableIter * iter, gpointer * key, gpointer * value)
134 {
135 gboolean found = FALSE;
136
137 iter->lpc = 0;
138 iter->key = NULL;
139 iter->value = NULL;
140 if (iter->nth < g_hash_table_size(iter->hash)) {
141 found = ! !g_hash_table_find(iter->hash, g_hash_table_nth_data, iter);
142 iter->nth++;
143 }
144 if (key)
145 *key = iter->key;
146 if (value)
147 *value = iter->value;
148 return found;
149 }
150
151 static inline void
152 g_hash_table_iter_remove(GHashTableIter * iter)
153 {
154 g_hash_table_remove(iter->hash, iter->key);
155 iter->nth--;
156 }
157
158 static inline int
159 g_strcmp0(const char *str1, const char *str2)
160 {
161 if (!str1)
162 return -(str1 != str2);
163 if (!str2)
164 return str1 != str2;
165 return strcmp(str1, str2);
166 }
167 # endif
168
169 # if !GLIB_CHECK_VERSION(2,28,0)
170 # include <string.h>
171
172 static inline void
173 g_list_free_full(GList * list, GDestroyNotify free_func)
174 {
175 g_list_foreach(list, (GFunc) free_func, NULL);
176 g_list_free(list);
177 }
178 # endif
179
180 # if SUPPORT_DBUS
181 # ifndef HAVE_DBUSBASICVALUE
182 # include <stdint.h>
183 # include <dbus/dbus.h>
184
185
186
187
188 typedef struct
189 {
190 uint32_t first32;
191 uint32_t second32;
192 } DBus8ByteStruct;
193
194
195
196
197
198
199
200
201
202
203
204 typedef union
205 {
206 unsigned char bytes[8];
207 int16_t i16;
208 uint16_t u16;
209 int32_t i32;
210 uint32_t u32;
211 uint32_t bool_val;
212 # ifdef DBUS_HAVE_INT64
213 int64_t i64;
214 uint64_t u64;
215 # endif
216 DBus8ByteStruct eight;
217 double dbl;
218 unsigned char byt;
219 char *str;
220 int fd;
221 } DBusBasicValue;
222 # endif
223 # endif
224
225
226 # include <errno.h>
227
228 # ifndef ENOTUNIQ
229 # define ENOTUNIQ 190
230 # endif
231
232 # ifndef ECOMM
233 # define ECOMM 191
234 # endif
235
236 # ifndef ELIBACC
237 # define ELIBACC 192
238 # endif
239
240 # ifndef EREMOTEIO
241 # define EREMOTEIO 193
242 # endif
243
244 # ifndef EUNATCH
245 # define EUNATCH 194
246 # endif
247
248 # ifndef ENOKEY
249 # define ENOKEY 195
250 # endif
251
252 # ifndef ENODATA
253 # define ENODATA 196
254 # endif
255
256 # ifndef ETIME
257 # define ETIME 197
258 # endif
259
260 # ifndef ENOSR
261 # define ENOSR 198
262 # endif
263
264 # ifndef ENOSTR
265 # define ENOSTR 199
266 # endif
267
268 # ifndef EKEYREJECTED
269 # define EKEYREJECTED 200
270 # endif
271
272
273
274
275 # ifdef __SUNPRO_C
276 # define __FUNCTION__ __func__
277 # endif
278
279 # ifdef __MY_UNKNOWN_C
280 # define __FUNCTION__ "__FUNCTION__"
281 # endif
282
283 #endif