File indexing completed on 2025-12-22 10:14:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef __G_UTILS_H__
0028 #define __G_UTILS_H__
0029
0030 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0031 #error "Only <glib.h> can be included directly."
0032 #endif
0033
0034 #include <glib/gtypes.h>
0035 #include <stdarg.h>
0036
0037 G_BEGIN_DECLS
0038
0039 GLIB_AVAILABLE_IN_ALL
0040 const gchar * g_get_user_name (void);
0041 GLIB_AVAILABLE_IN_ALL
0042 const gchar * g_get_real_name (void);
0043 GLIB_AVAILABLE_IN_ALL
0044 const gchar * g_get_home_dir (void);
0045 GLIB_AVAILABLE_IN_ALL
0046 const gchar * g_get_tmp_dir (void);
0047 GLIB_AVAILABLE_IN_ALL
0048 const gchar * g_get_host_name (void);
0049 GLIB_AVAILABLE_IN_ALL
0050 const gchar * g_get_prgname (void);
0051 GLIB_AVAILABLE_IN_ALL
0052 void g_set_prgname (const gchar *prgname);
0053 GLIB_AVAILABLE_IN_ALL
0054 const gchar * g_get_application_name (void);
0055 GLIB_AVAILABLE_IN_ALL
0056 void g_set_application_name (const gchar *application_name);
0057 GLIB_AVAILABLE_IN_2_64
0058 gchar * g_get_os_info (const gchar *key_name);
0059
0060
0061
0062
0063
0064
0065
0066
0067 #define G_OS_INFO_KEY_NAME \
0068 GLIB_AVAILABLE_MACRO_IN_2_64 \
0069 "NAME"
0070
0071
0072
0073
0074
0075
0076
0077
0078 #define G_OS_INFO_KEY_PRETTY_NAME \
0079 GLIB_AVAILABLE_MACRO_IN_2_64 \
0080 "PRETTY_NAME"
0081
0082
0083
0084
0085
0086
0087
0088
0089 #define G_OS_INFO_KEY_VERSION \
0090 GLIB_AVAILABLE_MACRO_IN_2_64 \
0091 "VERSION"
0092
0093
0094
0095
0096
0097
0098
0099
0100 #define G_OS_INFO_KEY_VERSION_CODENAME \
0101 GLIB_AVAILABLE_MACRO_IN_2_64 \
0102 "VERSION_CODENAME"
0103
0104
0105
0106
0107
0108
0109
0110
0111 #define G_OS_INFO_KEY_VERSION_ID \
0112 GLIB_AVAILABLE_MACRO_IN_2_64 \
0113 "VERSION_ID"
0114
0115
0116
0117
0118
0119
0120
0121
0122 #define G_OS_INFO_KEY_ID \
0123 GLIB_AVAILABLE_MACRO_IN_2_64 \
0124 "ID"
0125
0126
0127
0128
0129
0130
0131
0132
0133 #define G_OS_INFO_KEY_HOME_URL \
0134 GLIB_AVAILABLE_MACRO_IN_2_64 \
0135 "HOME_URL"
0136
0137
0138
0139
0140
0141
0142
0143
0144 #define G_OS_INFO_KEY_DOCUMENTATION_URL \
0145 GLIB_AVAILABLE_MACRO_IN_2_64 \
0146 "DOCUMENTATION_URL"
0147
0148
0149
0150
0151
0152
0153
0154
0155 #define G_OS_INFO_KEY_SUPPORT_URL \
0156 GLIB_AVAILABLE_MACRO_IN_2_64 \
0157 "SUPPORT_URL"
0158
0159
0160
0161
0162
0163
0164
0165
0166 #define G_OS_INFO_KEY_BUG_REPORT_URL \
0167 GLIB_AVAILABLE_MACRO_IN_2_64 \
0168 "BUG_REPORT_URL"
0169
0170
0171
0172
0173
0174
0175
0176
0177 #define G_OS_INFO_KEY_PRIVACY_POLICY_URL \
0178 GLIB_AVAILABLE_MACRO_IN_2_64 \
0179 "PRIVACY_POLICY_URL"
0180
0181 GLIB_AVAILABLE_IN_ALL
0182 void g_reload_user_special_dirs_cache (void);
0183 GLIB_AVAILABLE_IN_ALL
0184 const gchar * g_get_user_data_dir (void);
0185 GLIB_AVAILABLE_IN_ALL
0186 const gchar * g_get_user_config_dir (void);
0187 GLIB_AVAILABLE_IN_ALL
0188 const gchar * g_get_user_cache_dir (void);
0189 GLIB_AVAILABLE_IN_2_72
0190 const gchar * g_get_user_state_dir (void);
0191 GLIB_AVAILABLE_IN_ALL
0192 const gchar * const * g_get_system_data_dirs (void);
0193
0194 #ifdef G_OS_WIN32
0195
0196 GLIB_AVAILABLE_IN_ALL
0197 const gchar * const * g_win32_get_system_data_dirs_for_module (void (*address_of_function)(void));
0198 #endif
0199
0200 #if defined (G_OS_WIN32) && defined (G_CAN_INLINE)
0201
0202
0203
0204
0205 static inline const gchar * const *
0206 _g_win32_get_system_data_dirs (void)
0207 {
0208 return g_win32_get_system_data_dirs_for_module ((void (*)(void)) &_g_win32_get_system_data_dirs);
0209 }
0210 #define g_get_system_data_dirs _g_win32_get_system_data_dirs
0211 #endif
0212
0213 GLIB_AVAILABLE_IN_ALL
0214 const gchar * const * g_get_system_config_dirs (void);
0215
0216 GLIB_AVAILABLE_IN_ALL
0217 const gchar * g_get_user_runtime_dir (void);
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241 typedef enum {
0242 G_USER_DIRECTORY_DESKTOP,
0243 G_USER_DIRECTORY_DOCUMENTS,
0244 G_USER_DIRECTORY_DOWNLOAD,
0245 G_USER_DIRECTORY_MUSIC,
0246 G_USER_DIRECTORY_PICTURES,
0247 G_USER_DIRECTORY_PUBLIC_SHARE,
0248 G_USER_DIRECTORY_TEMPLATES,
0249 G_USER_DIRECTORY_VIDEOS,
0250
0251 G_USER_N_DIRECTORIES
0252 } GUserDirectory;
0253
0254 GLIB_AVAILABLE_IN_ALL
0255 const gchar * g_get_user_special_dir (GUserDirectory directory);
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 typedef struct _GDebugKey GDebugKey;
0266 struct _GDebugKey
0267 {
0268 const gchar *key;
0269 guint value;
0270 };
0271
0272
0273
0274 GLIB_AVAILABLE_IN_ALL
0275 guint g_parse_debug_string (const gchar *string,
0276 const GDebugKey *keys,
0277 guint nkeys);
0278
0279 GLIB_AVAILABLE_IN_ALL
0280 gint g_snprintf (gchar *string,
0281 gulong n,
0282 gchar const *format,
0283 ...) G_GNUC_PRINTF (3, 4);
0284 GLIB_AVAILABLE_IN_ALL
0285 gint g_vsnprintf (gchar *string,
0286 gulong n,
0287 gchar const *format,
0288 va_list args)
0289 G_GNUC_PRINTF(3, 0);
0290
0291 GLIB_AVAILABLE_IN_ALL
0292 void g_nullify_pointer (gpointer *nullify_location);
0293
0294 typedef enum
0295 {
0296 G_FORMAT_SIZE_DEFAULT = 0,
0297 G_FORMAT_SIZE_LONG_FORMAT = 1 << 0,
0298 G_FORMAT_SIZE_IEC_UNITS = 1 << 1,
0299 G_FORMAT_SIZE_BITS = 1 << 2,
0300 G_FORMAT_SIZE_ONLY_VALUE GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 1 << 3,
0301 G_FORMAT_SIZE_ONLY_UNIT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 1 << 4
0302 } GFormatSizeFlags;
0303
0304 GLIB_AVAILABLE_IN_2_30
0305 gchar *g_format_size_full (guint64 size,
0306 GFormatSizeFlags flags);
0307 GLIB_AVAILABLE_IN_2_30
0308 gchar *g_format_size (guint64 size);
0309
0310 GLIB_DEPRECATED_IN_2_30_FOR(g_format_size)
0311 gchar *g_format_size_for_display (goffset size);
0312
0313 #define g_ATEXIT(proc) (atexit (proc)) GLIB_DEPRECATED_MACRO_IN_2_32
0314 #define g_memmove(dest,src,len) \
0315 G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END GLIB_DEPRECATED_MACRO_IN_2_40_FOR(memmove)
0316
0317
0318
0319
0320
0321
0322
0323
0324 typedef void (*GVoidFunc) (void) GLIB_DEPRECATED_TYPE_IN_2_32;
0325 #define ATEXIT(proc) g_ATEXIT(proc) GLIB_DEPRECATED_MACRO_IN_2_32
0326
0327 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
0328 GLIB_DEPRECATED
0329 void g_atexit (GVoidFunc func);
0330 G_GNUC_END_IGNORE_DEPRECATIONS
0331
0332 #ifdef G_OS_WIN32
0333
0334
0335
0336
0337
0338
0339 #if (defined(__MINGW_H) && !defined(_STDLIB_H_)) || (defined(_MSC_VER) && !defined(_INC_STDLIB))
0340 int atexit (void (*)(void));
0341 #endif
0342 #define g_atexit(func) atexit(func) GLIB_DEPRECATED_MACRO_IN_2_32
0343 #endif
0344
0345
0346
0347 GLIB_AVAILABLE_IN_ALL
0348 gchar* g_find_program_in_path (const gchar *program);
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 #define g_bit_nth_lsf(mask, nth_bit) g_bit_nth_lsf_impl(mask, nth_bit)
0362 #define g_bit_nth_msf(mask, nth_bit) g_bit_nth_msf_impl(mask, nth_bit)
0363 #define g_bit_storage(number) g_bit_storage_impl(number)
0364
0365 GLIB_AVAILABLE_IN_ALL
0366 gint (g_bit_nth_lsf) (gulong mask,
0367 gint nth_bit);
0368 GLIB_AVAILABLE_IN_ALL
0369 gint (g_bit_nth_msf) (gulong mask,
0370 gint nth_bit);
0371 GLIB_AVAILABLE_IN_ALL
0372 guint (g_bit_storage) (gulong number);
0373
0374 static inline gint
0375 g_bit_nth_lsf_impl (gulong mask,
0376 gint nth_bit)
0377 {
0378 if (G_UNLIKELY (nth_bit < -1))
0379 nth_bit = -1;
0380 while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1))
0381 {
0382 nth_bit++;
0383 if (mask & (1UL << nth_bit))
0384 return nth_bit;
0385 }
0386 return -1;
0387 }
0388
0389 static inline gint
0390 g_bit_nth_msf_impl (gulong mask,
0391 gint nth_bit)
0392 {
0393 if (nth_bit < 0 || G_UNLIKELY (nth_bit > GLIB_SIZEOF_LONG * 8))
0394 nth_bit = GLIB_SIZEOF_LONG * 8;
0395 while (nth_bit > 0)
0396 {
0397 nth_bit--;
0398 if (mask & (1UL << nth_bit))
0399 return nth_bit;
0400 }
0401 return -1;
0402 }
0403
0404 static inline guint
0405 g_bit_storage_impl (gulong number)
0406 {
0407 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
0408 return G_LIKELY (number) ?
0409 ((GLIB_SIZEOF_LONG * 8U - 1) ^ (guint) __builtin_clzl(number)) + 1 : 1;
0410 #else
0411 guint n_bits = 0;
0412
0413 do
0414 {
0415 n_bits++;
0416 number >>= 1;
0417 }
0418 while (number);
0419 return n_bits;
0420 #endif
0421 }
0422
0423
0424 #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_50
0425 #ifndef G_OS_WIN32
0426 # include <stdlib.h>
0427 # define g_abort() abort ()
0428 #else
0429 G_NORETURN GLIB_AVAILABLE_IN_2_50 void g_abort (void) G_ANALYZER_NORETURN;
0430 #endif
0431 #endif
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450 #ifndef G_PLATFORM_WIN32
0451 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) GLIB_DEPRECATED_MACRO_IN_2_26
0452 #else
0453 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
0454 static char *dll_name; \
0455 \
0456 BOOL WINAPI \
0457 DllMain (HINSTANCE hinstDLL, \
0458 DWORD fdwReason, \
0459 LPVOID lpvReserved) \
0460 { \
0461 wchar_t wcbfr[1000]; \
0462 char *tem; \
0463 switch (fdwReason) \
0464 { \
0465 case DLL_PROCESS_ATTACH: \
0466 GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
0467 tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \
0468 dll_name = g_path_get_basename (tem); \
0469 g_free (tem); \
0470 break; \
0471 } \
0472 \
0473 return TRUE; \
0474 } GLIB_DEPRECATED_MACRO_IN_2_26
0475 #endif
0476
0477 G_END_DECLS
0478
0479 #endif