Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
glib-compat.h
Go to the documentation of this file.
1
12#ifndef GLIB_COMPAT_H
13#define GLIB_COMPAT_H
14
15#include "ws_symbol_export.h"
16#include "ws_attributes.h"
17
18#include <glib.h>
19#include <string.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25#if !GLIB_CHECK_VERSION(2, 61, 2)
26
27typedef volatile gint gatomicrefcount;
28
29typedef struct _GRealArray GRealArray;
31{
32 guint8 *data;
33 guint len;
34 guint alloc;
35 guint elt_size;
36 guint zero_terminated ;
37 guint clear;
38 gatomicrefcount ref_count;
39 GDestroyNotify clear_func;
40};
41
42static inline gboolean
43g_array_binary_search (GArray *array,
44 const void * target,
45 GCompareFunc compare_func,
46 guint *out_match_index)
47{
48 gboolean result = FALSE;
49 GRealArray *_array = (GRealArray *) array;
50 guint left, middle, right;
51 gint val;
52
53 g_return_val_if_fail (_array != NULL, FALSE);
54 g_return_val_if_fail (compare_func != NULL, FALSE);
55
56 if (G_LIKELY(_array->len))
57 {
58 left = 0;
59 right = _array->len - 1;
60
61 while (left <= right)
62 {
63 middle = left + (right - left) / 2;
64
65 val = compare_func (_array->data + (_array->elt_size * middle), target);
66 if (val == 0)
67 {
68 result = TRUE;
69 break;
70 }
71 else if (val < 0)
72 left = middle + 1;
73 else if (/* val > 0 && */ middle > 0)
74 right = middle - 1;
75 else
76 break; /* element not found */
77 }
78 }
79
80 if (result && out_match_index != NULL)
81 *out_match_index = middle;
82
83 return result;
84}
85#endif
86
87#if !GLIB_CHECK_VERSION(2, 64, 0)
88typedef struct _GRealPtrArray GRealPtrArray;
89
91{
92 gpointer *pdata;
93 guint len;
94 guint alloc;
95 gatomicrefcount ref_count;
96 guint8 null_terminated : 1; /* always either 0 or 1, so it can be added to array lengths */
97 GDestroyNotify element_free_func;
98};
99
100static inline gpointer
101g_array_steal (GArray *array,
102 gsize *len)
103{
104 GRealArray *rarray;
105 gpointer segment;
106
107 g_return_val_if_fail (array != NULL, NULL);
108
109 rarray = (GRealArray *) array;
110 segment = (gpointer) rarray->data;
111
112 if (len != NULL)
113 *len = rarray->len;
114
115 rarray->data = NULL;
116 rarray->len = 0;
117 rarray->alloc = 0;
118 return segment;
119}
120
121static inline gpointer *
122g_ptr_array_steal (GPtrArray *array,
123 gsize *len)
124{
125 GRealPtrArray *rarray;
126 gpointer *segment;
127
128 g_return_val_if_fail (array != NULL, NULL);
129
130 rarray = (GRealPtrArray *) array;
131 segment = (gpointer *) rarray->pdata;
132
133 if (len != NULL)
134 *len = rarray->len;
135
136 rarray->pdata = NULL;
137 rarray->len = 0;
138 rarray->alloc = 0;
139 return segment;
140}
141
142static inline guint8 *
143g_byte_array_steal (GByteArray *array,
144 gsize *len)
145{
146 return (guint8 *) g_array_steal ((GArray *) array, len);
147}
148#endif
149
150#if !GLIB_CHECK_VERSION(2, 68, 0)
151static inline void *
152g_memdup2(const void *mem, size_t byte_size)
153{
154 void * new_mem;
155
156 if (mem && byte_size != 0) {
157 new_mem = g_malloc(byte_size);
158 memcpy(new_mem, mem, byte_size);
159 }
160 else
161 new_mem = NULL;
162
163 return new_mem;
164}
165#endif
166
167#if !GLIB_CHECK_VERSION(2, 74, 0)
168#ifndef G_REGEX_DEFAULT
169#define G_REGEX_DEFAULT ((GRegexCompileFlags)0)
170#endif
171#endif
172
173#ifdef __cplusplus
174}
175#endif /* __cplusplus */
176
177#endif /* GLIB_COMPAT_H */
Definition glib-compat.h:31
Definition glib-compat.h:91
Definition tap-tcp-stream.h:43