williamr@2
|
1 |
/* GLIB - Library of useful routines for C programming
|
williamr@2
|
2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
williamr@2
|
3 |
* Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This library is free software; you can redistribute it and/or
|
williamr@2
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
williamr@2
|
7 |
* License as published by the Free Software Foundation; either
|
williamr@2
|
8 |
* version 2 of the License, or (at your option) any later version.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This library is distributed in the hope that it will be useful,
|
williamr@2
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
williamr@2
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
williamr@2
|
13 |
* Lesser General Public License for more details.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
williamr@2
|
16 |
* License along with this library; if not, write to the
|
williamr@2
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
williamr@2
|
18 |
* Boston, MA 02111-1307, USA.
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
/*
|
williamr@2
|
22 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
williamr@2
|
23 |
* file for a list of people on the GLib Team. See the ChangeLog
|
williamr@2
|
24 |
* files for a list of changes. These files are distributed with
|
williamr@2
|
25 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
williamr@2
|
26 |
*/
|
williamr@2
|
27 |
|
williamr@2
|
28 |
#ifndef __G_UTILS_H__
|
williamr@2
|
29 |
#define __G_UTILS_H__
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#include <_ansi.h>
|
williamr@2
|
32 |
#include <glib/gtypes.h>
|
williamr@2
|
33 |
#include <stdarg.h>
|
williamr@2
|
34 |
|
williamr@2
|
35 |
G_BEGIN_DECLS
|
williamr@2
|
36 |
|
williamr@2
|
37 |
#if defined(G_OS_WIN32) || defined(__SYMBIAN32__)
|
williamr@2
|
38 |
|
williamr@2
|
39 |
/* On Win32, the canonical directory separator is the backslash, and
|
williamr@2
|
40 |
* the search path separator is the semicolon. Note that also the
|
williamr@2
|
41 |
* (forward) slash works as directory separator.
|
williamr@2
|
42 |
*/
|
williamr@2
|
43 |
#define G_DIR_SEPARATOR '\\'
|
williamr@2
|
44 |
#define G_DIR_SEPARATOR_S "\\"
|
williamr@2
|
45 |
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
|
williamr@2
|
46 |
#define G_SEARCHPATH_SEPARATOR ';'
|
williamr@2
|
47 |
#define G_SEARCHPATH_SEPARATOR_S ";"
|
williamr@2
|
48 |
|
williamr@2
|
49 |
#else /* !G_OS_WIN32 */
|
williamr@2
|
50 |
|
williamr@2
|
51 |
/* Unix */
|
williamr@2
|
52 |
|
williamr@2
|
53 |
#define G_DIR_SEPARATOR '/'
|
williamr@2
|
54 |
#define G_DIR_SEPARATOR_S "/"
|
williamr@2
|
55 |
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
|
williamr@2
|
56 |
#define G_SEARCHPATH_SEPARATOR ':'
|
williamr@2
|
57 |
#define G_SEARCHPATH_SEPARATOR_S ":"
|
williamr@2
|
58 |
|
williamr@2
|
59 |
#endif /* !G_OS_WIN32 */
|
williamr@2
|
60 |
|
williamr@2
|
61 |
/* Define G_VA_COPY() to do the right thing for copying va_list variables.
|
williamr@2
|
62 |
* glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
|
williamr@2
|
63 |
*/
|
williamr@2
|
64 |
#if !defined (G_VA_COPY)
|
williamr@2
|
65 |
# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
|
williamr@2
|
66 |
# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
|
williamr@2
|
67 |
# elif defined (G_VA_COPY_AS_ARRAY)
|
williamr@2
|
68 |
# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
|
williamr@2
|
69 |
# else /* va_list is a pointer */
|
williamr@2
|
70 |
# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
|
williamr@2
|
71 |
# endif /* va_list is a pointer */
|
williamr@2
|
72 |
#endif /* !G_VA_COPY */
|
williamr@2
|
73 |
|
williamr@2
|
74 |
/* inlining hassle. for compilers that don't allow the `inline' keyword,
|
williamr@2
|
75 |
* mostly because of strict ANSI C compliance or dumbness, we try to fall
|
williamr@2
|
76 |
* back to either `__inline__' or `__inline'.
|
williamr@2
|
77 |
* G_CAN_INLINE is defined in glibconfig.h if the compiler seems to be
|
williamr@2
|
78 |
* actually *capable* to do function inlining, in which case inline
|
williamr@2
|
79 |
* function bodies do make sense. we also define G_INLINE_FUNC to properly
|
williamr@2
|
80 |
* export the function prototypes if no inlining can be performed.
|
williamr@2
|
81 |
* inline function bodies have to be special cased with G_CAN_INLINE and a
|
williamr@2
|
82 |
* .c file specific macro to allow one compiled instance with extern linkage
|
williamr@2
|
83 |
* of the functions by defining G_IMPLEMENT_INLINES and the .c file macro.
|
williamr@2
|
84 |
*/
|
williamr@2
|
85 |
#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
|
williamr@2
|
86 |
# undef inline
|
williamr@2
|
87 |
# define inline __inline__
|
williamr@2
|
88 |
#elif !defined (G_HAVE_INLINE)
|
williamr@2
|
89 |
# undef inline
|
williamr@2
|
90 |
# if defined (G_HAVE___INLINE__)
|
williamr@2
|
91 |
# define inline __inline__
|
williamr@2
|
92 |
# elif defined (G_HAVE___INLINE)
|
williamr@2
|
93 |
# define inline __inline
|
williamr@2
|
94 |
# else /* !inline && !__inline__ && !__inline */
|
williamr@2
|
95 |
# define inline /* don't inline, then */
|
williamr@2
|
96 |
# endif
|
williamr@2
|
97 |
#endif
|
williamr@2
|
98 |
#ifdef G_IMPLEMENT_INLINES
|
williamr@2
|
99 |
# define G_INLINE_FUNC
|
williamr@2
|
100 |
# undef G_CAN_INLINE
|
williamr@2
|
101 |
#elif defined (__GNUC__)
|
williamr@2
|
102 |
# ifdef __SYMBIAN32__
|
williamr@2
|
103 |
# define G_INLINE_FUNC extern __inline
|
williamr@2
|
104 |
# else
|
williamr@2
|
105 |
# define G_INLINE_FUNC extern inline
|
williamr@2
|
106 |
# endif
|
williamr@2
|
107 |
#elif defined (G_CAN_INLINE)
|
williamr@2
|
108 |
# ifdef __SYMBIAN32__
|
williamr@2
|
109 |
# define G_INLINE_FUNC static __inline
|
williamr@2
|
110 |
# else
|
williamr@2
|
111 |
# define G_INLINE_FUNC static inline
|
williamr@2
|
112 |
# endif
|
williamr@2
|
113 |
#else /* can't inline */
|
williamr@2
|
114 |
# define G_INLINE_FUNC
|
williamr@2
|
115 |
#endif /* !G_INLINE_FUNC */
|
williamr@2
|
116 |
|
williamr@2
|
117 |
/* Retrive static string info
|
williamr@2
|
118 |
*/
|
williamr@2
|
119 |
#ifdef G_OS_WIN32
|
williamr@2
|
120 |
#define g_get_user_name g_get_user_name_utf8
|
williamr@2
|
121 |
#define g_get_real_name g_get_real_name_utf8
|
williamr@2
|
122 |
#define g_get_home_dir g_get_home_dir_utf8
|
williamr@2
|
123 |
#define g_get_tmp_dir g_get_tmp_dir_utf8
|
williamr@2
|
124 |
#endif
|
williamr@2
|
125 |
|
williamr@2
|
126 |
IMPORT_C G_CONST_RETURN gchar* g_get_user_name (void);
|
williamr@2
|
127 |
IMPORT_C G_CONST_RETURN gchar* g_get_real_name (void);
|
williamr@2
|
128 |
IMPORT_C G_CONST_RETURN gchar* g_get_home_dir (void);
|
williamr@2
|
129 |
IMPORT_C G_CONST_RETURN gchar* g_get_tmp_dir (void);
|
williamr@2
|
130 |
IMPORT_C G_CONST_RETURN gchar* g_get_host_name (void);
|
williamr@2
|
131 |
IMPORT_C gchar* g_get_prgname (void);
|
williamr@2
|
132 |
IMPORT_C void g_set_prgname (const gchar *prgname);
|
williamr@2
|
133 |
IMPORT_C G_CONST_RETURN gchar* g_get_application_name (void);
|
williamr@2
|
134 |
IMPORT_C void g_set_application_name (const gchar *application_name);
|
williamr@2
|
135 |
|
williamr@2
|
136 |
IMPORT_C G_CONST_RETURN gchar* g_get_user_data_dir (void);
|
williamr@2
|
137 |
IMPORT_C G_CONST_RETURN gchar* g_get_user_config_dir (void);
|
williamr@2
|
138 |
IMPORT_C G_CONST_RETURN gchar* g_get_user_cache_dir (void);
|
williamr@2
|
139 |
IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_data_dirs (void);
|
williamr@2
|
140 |
|
williamr@2
|
141 |
#ifdef G_OS_WIN32
|
williamr@2
|
142 |
G_CONST_RETURN gchar* G_CONST_RETURN * g_win32_get_system_data_dirs_for_module (gconstpointer address);
|
williamr@2
|
143 |
#endif
|
williamr@2
|
144 |
|
williamr@2
|
145 |
#if defined (G_OS_WIN32) && defined (G_CAN_INLINE) && !defined (__cplusplus)
|
williamr@2
|
146 |
static inline G_CONST_RETURN gchar * G_CONST_RETURN *
|
williamr@2
|
147 |
g_win32_get_system_data_dirs (void)
|
williamr@2
|
148 |
{
|
williamr@2
|
149 |
return g_win32_get_system_data_dirs_for_module ((gconstpointer) &g_win32_get_system_data_dirs);
|
williamr@2
|
150 |
}
|
williamr@2
|
151 |
#define g_get_system_data_dirs g_win32_get_system_data_dirs
|
williamr@2
|
152 |
#endif
|
williamr@2
|
153 |
|
williamr@2
|
154 |
IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_system_config_dirs (void);
|
williamr@2
|
155 |
|
williamr@2
|
156 |
IMPORT_C G_CONST_RETURN gchar* G_CONST_RETURN * g_get_language_names (void);
|
williamr@2
|
157 |
|
williamr@2
|
158 |
typedef struct _GDebugKey GDebugKey;
|
williamr@2
|
159 |
struct _GDebugKey
|
williamr@2
|
160 |
{
|
williamr@2
|
161 |
gchar *key;
|
williamr@2
|
162 |
guint value;
|
williamr@2
|
163 |
};
|
williamr@2
|
164 |
|
williamr@2
|
165 |
/* Miscellaneous utility functions
|
williamr@2
|
166 |
*/
|
williamr@2
|
167 |
IMPORT_C guint g_parse_debug_string (const gchar *string,
|
williamr@2
|
168 |
const GDebugKey *keys,
|
williamr@2
|
169 |
guint nkeys);
|
williamr@2
|
170 |
|
williamr@2
|
171 |
IMPORT_C gint g_snprintf (gchar *string,
|
williamr@2
|
172 |
gulong n,
|
williamr@2
|
173 |
gchar const *format,
|
williamr@2
|
174 |
...) G_GNUC_PRINTF (3, 4);
|
williamr@2
|
175 |
IMPORT_C gint g_vsnprintf (gchar *string,
|
williamr@2
|
176 |
gulong n,
|
williamr@2
|
177 |
gchar const *format,
|
williamr@2
|
178 |
va_list args);
|
williamr@2
|
179 |
|
williamr@2
|
180 |
/* Check if a file name is an absolute path */
|
williamr@2
|
181 |
IMPORT_C gboolean g_path_is_absolute (const gchar *file_name);
|
williamr@2
|
182 |
|
williamr@2
|
183 |
/* In case of absolute paths, skip the root part */
|
williamr@2
|
184 |
IMPORT_C G_CONST_RETURN gchar* g_path_skip_root (const gchar *file_name);
|
williamr@2
|
185 |
|
williamr@2
|
186 |
#ifndef G_DISABLE_DEPRECATED
|
williamr@2
|
187 |
|
williamr@2
|
188 |
/* These two functions are deprecated and will be removed in the next
|
williamr@2
|
189 |
* major release of GLib. Use g_path_get_dirname/g_path_get_basename
|
williamr@2
|
190 |
* instead. Whatch out! The string returned by g_path_get_basename
|
williamr@2
|
191 |
* must be g_freed, while the string returned by g_basename must not.*/
|
williamr@2
|
192 |
IMPORT_C G_CONST_RETURN gchar* g_basename (const gchar *file_name);
|
williamr@2
|
193 |
#define g_dirname g_path_get_dirname
|
williamr@2
|
194 |
|
williamr@2
|
195 |
#endif /* G_DISABLE_DEPRECATED */
|
williamr@2
|
196 |
|
williamr@2
|
197 |
#ifdef G_OS_WIN32
|
williamr@2
|
198 |
#define g_get_current_dir g_get_current_dir_utf8
|
williamr@2
|
199 |
#endif
|
williamr@2
|
200 |
|
williamr@2
|
201 |
/* The returned strings are newly allocated with g_malloc() */
|
williamr@2
|
202 |
IMPORT_C gchar* g_get_current_dir (void);
|
williamr@2
|
203 |
IMPORT_C gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
|
williamr@2
|
204 |
IMPORT_C gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
|
williamr@2
|
205 |
|
williamr@2
|
206 |
/* Set the pointer at the specified location to NULL */
|
williamr@2
|
207 |
IMPORT_C void g_nullify_pointer (gpointer *nullify_location);
|
williamr@2
|
208 |
|
williamr@2
|
209 |
/* return the environment string for the variable. The returned memory
|
williamr@2
|
210 |
* must not be freed. */
|
williamr@2
|
211 |
#ifdef G_OS_WIN32
|
williamr@2
|
212 |
#define g_getenv g_getenv_utf8
|
williamr@2
|
213 |
#define g_setenv g_setenv_utf8
|
williamr@2
|
214 |
#define g_unsetenv g_unsetenv_utf8
|
williamr@2
|
215 |
#define g_find_program_in_path g_find_program_in_path_utf8
|
williamr@2
|
216 |
#endif
|
williamr@2
|
217 |
|
williamr@2
|
218 |
IMPORT_C G_CONST_RETURN gchar* g_getenv (const gchar *variable);
|
williamr@2
|
219 |
IMPORT_C gboolean g_setenv (const gchar *variable,
|
williamr@2
|
220 |
const gchar *value,
|
williamr@2
|
221 |
gboolean overwrite);
|
williamr@2
|
222 |
IMPORT_C void g_unsetenv (const gchar *variable);
|
williamr@2
|
223 |
IMPORT_C gchar** g_listenv (void);
|
williamr@2
|
224 |
const gchar* _g_getenv_nomalloc (const gchar *variable,
|
williamr@2
|
225 |
gchar buffer[1024]);
|
williamr@2
|
226 |
|
williamr@2
|
227 |
/* we try to provide a usefull equivalent for ATEXIT if it is
|
williamr@2
|
228 |
* not defined, but use is actually abandoned. people should
|
williamr@2
|
229 |
* use g_atexit() instead.
|
williamr@2
|
230 |
*/
|
williamr@2
|
231 |
typedef void (*GVoidFunc) (void);
|
williamr@2
|
232 |
#ifndef ATEXIT
|
williamr@2
|
233 |
# define ATEXIT(proc) g_ATEXIT(proc)
|
williamr@2
|
234 |
#else
|
williamr@2
|
235 |
# define G_NATIVE_ATEXIT
|
williamr@2
|
236 |
#endif /* ATEXIT */
|
williamr@2
|
237 |
/* we use a GLib function as a replacement for ATEXIT, so
|
williamr@2
|
238 |
* the programmer is not required to check the return value
|
williamr@2
|
239 |
* (if there is any in the implementation) and doesn't encounter
|
williamr@2
|
240 |
* missing include files.
|
williamr@2
|
241 |
*/
|
williamr@2
|
242 |
IMPORT_C void g_atexit (GVoidFunc func);
|
williamr@2
|
243 |
|
williamr@2
|
244 |
#ifdef G_OS_WIN32
|
williamr@2
|
245 |
/* It's a bad idea to wrap atexit() on Windows. If the GLib DLL calls
|
williamr@2
|
246 |
* atexit(), the function will be called when the GLib DLL is detached
|
williamr@2
|
247 |
* from the program, which is not what the caller wants. The caller
|
williamr@2
|
248 |
* wants the function to be called when it *itself* exits (or is
|
williamr@2
|
249 |
* detached, in case the caller, too, is a DLL).
|
williamr@2
|
250 |
*/
|
williamr@2
|
251 |
int atexit (void (*)(void));
|
williamr@2
|
252 |
#define g_atexit(func) atexit(func)
|
williamr@2
|
253 |
#endif
|
williamr@2
|
254 |
|
williamr@2
|
255 |
/* Look for an executable in PATH, following execvp() rules */
|
williamr@2
|
256 |
IMPORT_C gchar* g_find_program_in_path (const gchar *program);
|
williamr@2
|
257 |
|
williamr@2
|
258 |
/* Bit tests
|
williamr@2
|
259 |
*/
|
williamr@2
|
260 |
G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask,
|
williamr@2
|
261 |
gint nth_bit);
|
williamr@2
|
262 |
G_INLINE_FUNC gint g_bit_nth_msf (gulong mask,
|
williamr@2
|
263 |
gint nth_bit);
|
williamr@2
|
264 |
G_INLINE_FUNC guint g_bit_storage (gulong number);
|
williamr@2
|
265 |
|
williamr@2
|
266 |
/* Trash Stacks
|
williamr@2
|
267 |
* elements need to be >= sizeof (gpointer)
|
williamr@2
|
268 |
*/
|
williamr@2
|
269 |
typedef struct _GTrashStack GTrashStack;
|
williamr@2
|
270 |
struct _GTrashStack
|
williamr@2
|
271 |
{
|
williamr@2
|
272 |
GTrashStack *next;
|
williamr@2
|
273 |
};
|
williamr@2
|
274 |
|
williamr@2
|
275 |
G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
|
williamr@2
|
276 |
gpointer data_p);
|
williamr@2
|
277 |
G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
|
williamr@2
|
278 |
G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
|
williamr@2
|
279 |
G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
|
williamr@2
|
280 |
|
williamr@2
|
281 |
/* inline function implementations
|
williamr@2
|
282 |
*/
|
williamr@2
|
283 |
#if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
|
williamr@2
|
284 |
G_INLINE_FUNC gint
|
williamr@2
|
285 |
g_bit_nth_lsf (gulong mask,
|
williamr@2
|
286 |
gint nth_bit)
|
williamr@2
|
287 |
{
|
williamr@2
|
288 |
do
|
williamr@2
|
289 |
{
|
williamr@2
|
290 |
nth_bit++;
|
williamr@2
|
291 |
if (mask & (1UL << nth_bit))
|
williamr@2
|
292 |
return nth_bit;
|
williamr@2
|
293 |
}
|
williamr@2
|
294 |
while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1));
|
williamr@2
|
295 |
return -1;
|
williamr@2
|
296 |
}
|
williamr@2
|
297 |
G_INLINE_FUNC gint
|
williamr@2
|
298 |
g_bit_nth_msf (gulong mask,
|
williamr@2
|
299 |
gint nth_bit)
|
williamr@2
|
300 |
{
|
williamr@2
|
301 |
if (nth_bit < 0)
|
williamr@2
|
302 |
nth_bit = GLIB_SIZEOF_LONG * 8;
|
williamr@2
|
303 |
do
|
williamr@2
|
304 |
{
|
williamr@2
|
305 |
nth_bit--;
|
williamr@2
|
306 |
if (mask & (1UL << nth_bit))
|
williamr@2
|
307 |
return nth_bit;
|
williamr@2
|
308 |
}
|
williamr@2
|
309 |
while (nth_bit > 0);
|
williamr@2
|
310 |
return -1;
|
williamr@2
|
311 |
}
|
williamr@2
|
312 |
G_INLINE_FUNC guint
|
williamr@2
|
313 |
g_bit_storage (gulong number)
|
williamr@2
|
314 |
{
|
williamr@2
|
315 |
register guint n_bits = 0;
|
williamr@2
|
316 |
|
williamr@2
|
317 |
do
|
williamr@2
|
318 |
{
|
williamr@2
|
319 |
n_bits++;
|
williamr@2
|
320 |
number >>= 1;
|
williamr@2
|
321 |
}
|
williamr@2
|
322 |
while (number);
|
williamr@2
|
323 |
return n_bits;
|
williamr@2
|
324 |
}
|
williamr@2
|
325 |
G_INLINE_FUNC void
|
williamr@2
|
326 |
g_trash_stack_push (GTrashStack **stack_p,
|
williamr@2
|
327 |
gpointer data_p)
|
williamr@2
|
328 |
{
|
williamr@2
|
329 |
GTrashStack *data = (GTrashStack *) data_p;
|
williamr@2
|
330 |
|
williamr@2
|
331 |
data->next = *stack_p;
|
williamr@2
|
332 |
*stack_p = data;
|
williamr@2
|
333 |
}
|
williamr@2
|
334 |
G_INLINE_FUNC gpointer
|
williamr@2
|
335 |
g_trash_stack_pop (GTrashStack **stack_p)
|
williamr@2
|
336 |
{
|
williamr@2
|
337 |
GTrashStack *data;
|
williamr@2
|
338 |
|
williamr@2
|
339 |
data = *stack_p;
|
williamr@2
|
340 |
if (data)
|
williamr@2
|
341 |
{
|
williamr@2
|
342 |
*stack_p = data->next;
|
williamr@2
|
343 |
/* NULLify private pointer here, most platforms store NULL as
|
williamr@2
|
344 |
* subsequent 0 bytes
|
williamr@2
|
345 |
*/
|
williamr@2
|
346 |
data->next = NULL;
|
williamr@2
|
347 |
}
|
williamr@2
|
348 |
|
williamr@2
|
349 |
return data;
|
williamr@2
|
350 |
}
|
williamr@2
|
351 |
G_INLINE_FUNC gpointer
|
williamr@2
|
352 |
g_trash_stack_peek (GTrashStack **stack_p)
|
williamr@2
|
353 |
{
|
williamr@2
|
354 |
GTrashStack *data;
|
williamr@2
|
355 |
|
williamr@2
|
356 |
data = *stack_p;
|
williamr@2
|
357 |
|
williamr@2
|
358 |
return data;
|
williamr@2
|
359 |
}
|
williamr@2
|
360 |
G_INLINE_FUNC guint
|
williamr@2
|
361 |
g_trash_stack_height (GTrashStack **stack_p)
|
williamr@2
|
362 |
{
|
williamr@2
|
363 |
GTrashStack *data;
|
williamr@2
|
364 |
guint i = 0;
|
williamr@2
|
365 |
|
williamr@2
|
366 |
for (data = *stack_p; data; data = data->next)
|
williamr@2
|
367 |
i++;
|
williamr@2
|
368 |
|
williamr@2
|
369 |
return i;
|
williamr@2
|
370 |
}
|
williamr@2
|
371 |
#endif /* G_CAN_INLINE || __G_UTILS_C__ */
|
williamr@2
|
372 |
|
williamr@2
|
373 |
/* Glib version.
|
williamr@2
|
374 |
* we prefix variable declarations so they can
|
williamr@2
|
375 |
* properly get exported in windows dlls.
|
williamr@2
|
376 |
*/
|
williamr@2
|
377 |
GLIB_VAR const guint glib_major_version;
|
williamr@2
|
378 |
GLIB_VAR const guint glib_minor_version;
|
williamr@2
|
379 |
GLIB_VAR const guint glib_micro_version;
|
williamr@2
|
380 |
GLIB_VAR const guint glib_interface_age;
|
williamr@2
|
381 |
GLIB_VAR const guint glib_binary_age;
|
williamr@2
|
382 |
|
williamr@2
|
383 |
#ifdef __SYMBIAN32__
|
williamr@2
|
384 |
IMPORT_C const guint *_glib_major_version();
|
williamr@2
|
385 |
IMPORT_C const guint *_glib_minor_version();
|
williamr@2
|
386 |
IMPORT_C const guint *_glib_micro_version();
|
williamr@2
|
387 |
IMPORT_C const guint *_glib_interface_age();
|
williamr@2
|
388 |
IMPORT_C const guint *_glib_binary_age();
|
williamr@2
|
389 |
#endif /* __SYMBIAN32__ */
|
williamr@2
|
390 |
|
williamr@2
|
391 |
IMPORT_C const gchar * glib_check_version (guint required_major,
|
williamr@2
|
392 |
guint required_minor,
|
williamr@2
|
393 |
guint required_micro);
|
williamr@2
|
394 |
|
williamr@2
|
395 |
#define GLIB_CHECK_VERSION(major,minor,micro) \
|
williamr@2
|
396 |
(GLIB_MAJOR_VERSION > (major) || \
|
williamr@2
|
397 |
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
|
williamr@2
|
398 |
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
|
williamr@2
|
399 |
GLIB_MICRO_VERSION >= (micro)))
|
williamr@2
|
400 |
|
williamr@2
|
401 |
G_END_DECLS
|
williamr@2
|
402 |
|
williamr@2
|
403 |
/*
|
williamr@2
|
404 |
* On Windows, this macro defines a DllMain function that stores the
|
williamr@2
|
405 |
* actual DLL name that the code being compiled will be included in.
|
williamr@2
|
406 |
* STATIC should be empty or 'static'. DLL_NAME is the name of the
|
williamr@2
|
407 |
* (pointer to the) char array where the DLL name will be stored. If
|
williamr@2
|
408 |
* this is used, you must also include <windows.h>. If you need a more complex
|
williamr@2
|
409 |
* DLL entry point function, you cannot use this.
|
williamr@2
|
410 |
*
|
williamr@2
|
411 |
* On non-Windows platforms, expands to nothing.
|
williamr@2
|
412 |
*/
|
williamr@2
|
413 |
|
williamr@2
|
414 |
#ifndef G_PLATFORM_WIN32
|
williamr@2
|
415 |
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
|
williamr@2
|
416 |
#else
|
williamr@2
|
417 |
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
|
williamr@2
|
418 |
static char *dll_name; \
|
williamr@2
|
419 |
\
|
williamr@2
|
420 |
BOOL WINAPI \
|
williamr@2
|
421 |
DllMain (HINSTANCE hinstDLL, \
|
williamr@2
|
422 |
DWORD fdwReason, \
|
williamr@2
|
423 |
LPVOID lpvReserved) \
|
williamr@2
|
424 |
{ \
|
williamr@2
|
425 |
wchar_t wcbfr[1000]; \
|
williamr@2
|
426 |
char cpbfr[1000]; \
|
williamr@2
|
427 |
char *tem; \
|
williamr@2
|
428 |
switch (fdwReason) \
|
williamr@2
|
429 |
{ \
|
williamr@2
|
430 |
case DLL_PROCESS_ATTACH: \
|
williamr@2
|
431 |
if (GetVersion () < 0x80000000) \
|
williamr@2
|
432 |
{ \
|
williamr@2
|
433 |
GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
|
williamr@2
|
434 |
tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \
|
williamr@2
|
435 |
dll_name = g_path_get_basename (tem); \
|
williamr@2
|
436 |
g_free (tem); \
|
williamr@2
|
437 |
} \
|
williamr@2
|
438 |
else \
|
williamr@2
|
439 |
{ \
|
williamr@2
|
440 |
GetModuleFileNameA ((HMODULE) hinstDLL, cpbfr, G_N_ELEMENTS (cpbfr)); \
|
williamr@2
|
441 |
tem = g_locale_to_utf8 (cpbfr, -1, NULL, NULL, NULL); \
|
williamr@2
|
442 |
dll_name = g_path_get_basename (tem); \
|
williamr@2
|
443 |
g_free (tem); \
|
williamr@2
|
444 |
} \
|
williamr@2
|
445 |
break; \
|
williamr@2
|
446 |
} \
|
williamr@2
|
447 |
\
|
williamr@2
|
448 |
return TRUE; \
|
williamr@2
|
449 |
}
|
williamr@2
|
450 |
#endif /* G_PLATFORM_WIN32 */
|
williamr@2
|
451 |
|
williamr@2
|
452 |
#endif /* __G_UTILS_H__ */
|