1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
28 * MT safe for the unix part, FIXME: make the win32 part MT safe as well.
45 #include <sys/types.h>
46 #ifdef HAVE_SYS_PARAM_H
47 #include <sys/param.h>
50 /* implement gutils's inline functions
52 #define G_IMPLEMENT_INLINES 1
55 #include "gprintfint.h"
56 #include "gthreadinit.h"
60 #define G_PATH_LENGTH MAXPATHLEN
61 #elif defined (PATH_MAX)
62 #define G_PATH_LENGTH PATH_MAX
63 #elif defined (_PC_PATH_MAX)
64 #define G_PATH_LENGTH sysconf(_PC_PATH_MAX)
66 #define G_PATH_LENGTH 2048
69 #ifdef G_PLATFORM_WIN32
70 # define STRICT /* Strict typing, please */
73 # ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
74 # define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
75 # define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
77 # include <lmcons.h> /* For UNLEN */
78 #endif /* G_PLATFORM_WIN32 */
83 /* older SDK (e.g. msvc 5.0) does not have these*/
84 # ifndef CSIDL_INTERNET_CACHE
85 # define CSIDL_INTERNET_CACHE 32
87 # ifndef CSIDL_COMMON_APPDATA
88 # define CSIDL_COMMON_APPDATA 35
90 # ifndef CSIDL_COMMON_DOCUMENTS
91 # define CSIDL_COMMON_DOCUMENTS 46
93 # ifndef CSIDL_PROFILE
94 # define CSIDL_PROFILE 40
100 #include <langinfo.h>
103 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
107 const guint glib_major_version = GLIB_MAJOR_VERSION;
108 const guint glib_minor_version = GLIB_MINOR_VERSION;
109 const guint glib_micro_version = GLIB_MICRO_VERSION;
110 const guint glib_interface_age = GLIB_INTERFACE_AGE;
111 const guint glib_binary_age = GLIB_BINARY_AGE;
113 #ifdef G_PLATFORM_WIN32
115 G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name)
120 * glib_check_version:
121 * @required_major: the required major version.
122 * @required_minor: the required major version.
123 * @required_micro: the required major version.
125 * Checks that the GLib library in use is compatible with the
126 * given version. Generally you would pass in the constants
127 * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
128 * as the three arguments to this function; that produces
129 * a check that the library in use is compatible with
130 * the version of GLib the application or module was compiled
133 * Compatibility is defined by two things: first the version
134 * of the running library is newer than the version
135 * @required_major.required_minor.@required_micro. Second
136 * the running library must be binary compatible with the
137 * version @required_major.required_minor.@required_micro
138 * (same major version.)
140 * Return value: %NULL if the GLib library is compatible with the
141 * given version, or a string describing the version mismatch.
142 * The returned string is owned by GLib and must not be modified
148 glib_check_version (guint required_major,
149 guint required_minor,
150 guint required_micro)
152 gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
153 gint required_effective_micro = 100 * required_minor + required_micro;
155 if (required_major > GLIB_MAJOR_VERSION)
156 return "GLib version too old (major mismatch)";
157 if (required_major < GLIB_MAJOR_VERSION)
158 return "GLib version too new (major mismatch)";
159 if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
160 return "GLib version too new (micro mismatch)";
161 if (required_effective_micro > glib_effective_micro)
162 return "GLib version too old (micro mismatch)";
166 #if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY)
169 * @dest: the destination address to copy the bytes to.
170 * @src: the source address to copy the bytes from.
171 * @len: the number of bytes to copy.
173 * Copies a block of memory @len bytes long, from @src to @dest.
174 * The source and destination areas may overlap.
176 * In order to use this function, you must include
177 * <filename>string.h</filename> yourself, because this macro will
178 * typically simply resolve to memmove() and GLib does not include
179 * <filename>string.h</filename> for you.
182 g_memmove (gpointer dest,
186 gchar* destptr = dest;
187 const gchar* srcptr = src;
188 if (src + len < dest || dest + len < src)
190 bcopy (src, dest, len);
193 else if (dest <= src)
196 *(destptr++) = *(srcptr++);
203 *(--destptr) = *(--srcptr);
206 #endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */
210 * @func: the function to call on normal program termination.
212 * Specifies a function to be called at normal program termination.
215 g_atexit (GVoidFunc func)
218 const gchar *error = NULL;
220 /* keep this in sync with glib.h */
222 #ifdef G_NATIVE_ATEXIT
223 result = ATEXIT (func);
225 error = g_strerror (errno);
226 #elif defined (HAVE_ATEXIT)
227 # ifdef NeXT /* @#%@! NeXTStep */
228 result = !atexit ((void (*)(void)) func);
230 error = g_strerror (errno);
232 result = atexit ((void (*)(void)) func);
234 error = g_strerror (errno);
236 #elif defined (HAVE_ON_EXIT)
237 result = on_exit ((void (*)(int, void *)) func, NULL);
239 error = g_strerror (errno);
242 error = "no implementation";
243 #endif /* G_NATIVE_ATEXIT */
246 g_error ("Could not register atexit() function: %s", error);
249 /* Based on execvp() from GNU Libc.
250 * Some of this code is cut-and-pasted into gspawn.c
254 my_strchrnul (const gchar *str,
257 gchar *p = (gchar*)str;
258 while (*p && (*p != c))
266 static gchar *inner_find_program_in_path (const gchar *program);
269 g_find_program_in_path (const gchar *program)
271 const gchar *last_dot = strrchr (program, '.');
273 if (last_dot == NULL ||
274 strchr (last_dot, '\\') != NULL ||
275 strchr (last_dot, '/') != NULL)
277 const gint program_length = strlen (program);
278 gchar *pathext = g_build_path (";",
279 ".exe;.cmd;.bat;.com",
280 g_getenv ("PATHEXT"),
283 gchar *decorated_program;
289 gchar *q = my_strchrnul (p, ';');
291 decorated_program = g_malloc (program_length + (q-p) + 1);
292 memcpy (decorated_program, program, program_length);
293 memcpy (decorated_program+program_length, p, q-p);
294 decorated_program [program_length + (q-p)] = '\0';
296 retval = inner_find_program_in_path (decorated_program);
297 g_free (decorated_program);
305 } while (*p++ != '\0');
310 return inner_find_program_in_path (program);
316 * g_find_program_in_path:
317 * @program: a program name in the GLib file name encoding
319 * Locates the first executable named @program in the user's path, in the
320 * same way that execvp() would locate it. Returns an allocated string
321 * with the absolute path name, or %NULL if the program is not found in
322 * the path. If @program is already an absolute path, returns a copy of
323 * @program if @program exists and is executable, and %NULL otherwise.
325 * On Windows, if @program does not have a file type suffix, tries
326 * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
327 * the <envar>PATHEXT</envar> environment variable.
329 * On Windows, it looks for the file in the same way as CreateProcess()
330 * would. This means first in the directory where the executing
331 * program was loaded from, then in the current directory, then in the
332 * Windows 32-bit system directory, then in the Windows directory, and
333 * finally in the directories in the <envar>PATH</envar> environment
334 * variable. If the program is found, the return value contains the
335 * full name including the type suffix.
337 * Return value: absolute path, or %NULL
341 inner_find_program_in_path (const gchar *program)
344 g_find_program_in_path (const gchar *program)
347 const gchar *path, *p;
348 gchar *name, *freeme;
350 const gchar *path_copy;
351 gchar *filename = NULL, *appdir = NULL;
352 gchar *sysdir = NULL, *windir = NULL;
357 g_return_val_if_fail (program != NULL, NULL);
359 /* If it is an absolute path, or a relative path including subdirectories,
360 * don't look in PATH.
362 if (g_path_is_absolute (program)
363 || strchr (program, G_DIR_SEPARATOR) != NULL
365 || strchr (program, '/') != NULL
369 if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
370 !g_file_test (program, G_FILE_TEST_IS_DIR))
371 return g_strdup (program);
376 path = g_getenv ("PATH");
377 #if defined(G_OS_UNIX) || defined(G_OS_BEOS)
380 /* There is no `PATH' in the environment. The default
381 * search path in GNU libc is the current directory followed by
382 * the path `confstr' returns for `_CS_PATH'.
385 /* In GLib we put . last, for security, and don't use the
386 * unportable confstr(); UNIX98 does not actually specify
387 * what to search if PATH is unset. POSIX may, dunno.
390 path = "/bin:/usr/bin:.";
393 if (G_WIN32_HAVE_WIDECHAR_API ())
396 wchar_t wfilename[MAXPATHLEN], wsysdir[MAXPATHLEN],
399 n = GetModuleFileNameW (NULL, wfilename, MAXPATHLEN);
400 if (n > 0 && n < MAXPATHLEN)
401 filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
403 n = GetSystemDirectoryW (wsysdir, MAXPATHLEN);
404 if (n > 0 && n < MAXPATHLEN)
405 sysdir = g_utf16_to_utf8 (wsysdir, -1, NULL, NULL, NULL);
407 n = GetWindowsDirectoryW (wwindir, MAXPATHLEN);
408 if (n > 0 && n < MAXPATHLEN)
409 windir = g_utf16_to_utf8 (wwindir, -1, NULL, NULL, NULL);
414 gchar cpfilename[MAXPATHLEN], cpsysdir[MAXPATHLEN],
415 cpwindir[MAXPATHLEN];
417 n = GetModuleFileNameA (NULL, cpfilename, MAXPATHLEN);
418 if (n > 0 && n < MAXPATHLEN)
419 filename = g_locale_to_utf8 (cpfilename, -1, NULL, NULL, NULL);
421 n = GetSystemDirectoryA (cpsysdir, MAXPATHLEN);
422 if (n > 0 && n < MAXPATHLEN)
423 sysdir = g_locale_to_utf8 (cpsysdir, -1, NULL, NULL, NULL);
425 n = GetWindowsDirectoryA (cpwindir, MAXPATHLEN);
426 if (n > 0 && n < MAXPATHLEN)
427 windir = g_locale_to_utf8 (cpwindir, -1, NULL, NULL, NULL);
432 appdir = g_path_get_dirname (filename);
436 path = g_strdup (path);
440 const gchar *tem = path;
441 path = g_strconcat (windir, ";", path, NULL);
442 g_free ((gchar *) tem);
448 const gchar *tem = path;
449 path = g_strconcat (sysdir, ";", path, NULL);
450 g_free ((gchar *) tem);
455 const gchar *tem = path;
456 path = g_strconcat (".;", path, NULL);
457 g_free ((gchar *) tem);
462 const gchar *tem = path;
463 path = g_strconcat (appdir, ";", path, NULL);
464 g_free ((gchar *) tem);
471 len = strlen (program) + 1;
472 pathlen = strlen (path);
473 freeme = name = g_malloc (pathlen + len + 1);
475 /* Copy the file name at the top, including '\0' */
476 memcpy (name + pathlen + 1, program, len);
477 name = name + pathlen;
478 /* And add the slash before the filename */
479 *name = G_DIR_SEPARATOR;
487 p = my_strchrnul (path, G_SEARCHPATH_SEPARATOR);
490 /* Two adjacent colons, or a colon at the beginning or the end
491 * of `PATH' means to search the current directory.
495 startp = memcpy (name - (p - path), path, p - path);
497 if (g_file_test (startp, G_FILE_TEST_IS_EXECUTABLE) &&
498 !g_file_test (startp, G_FILE_TEST_IS_DIR))
501 ret = g_strdup (startp);
504 g_free ((gchar *) path_copy);
509 while (*p++ != '\0');
513 g_free ((gchar *) path_copy);
520 * g_parse_debug_string:
521 * @string: a list of debug options separated by ':' or "all"
523 * @keys: pointer to an array of #GDebugKey which associate
524 * strings with bit flags.
525 * @nkeys: the number of #GDebugKey<!-- -->s in the array.
527 * Parses a string containing debugging options separated
528 * by ':' into a %guint containing bit flags. This is used
529 * within GDK and GTK+ to parse the debug options passed on the
530 * command line or through environment variables.
532 * Returns: the combined set of bit flags.
535 g_parse_debug_string (const gchar *string,
536 const GDebugKey *keys,
542 g_return_val_if_fail (string != NULL, 0);
544 if (!g_ascii_strcasecmp (string, "all"))
546 for (i=0; i<nkeys; i++)
547 result |= keys[i].value;
551 const gchar *p = string;
553 gboolean done = FALSE;
564 for (i=0; i<nkeys; i++)
565 if (g_ascii_strncasecmp (keys[i].key, p, q - p) == 0 &&
566 keys[i].key[q - p] == '\0')
567 result |= keys[i].value;
578 * @file_name: the name of the file.
580 * Gets the name of the file without any leading directory components.
581 * It returns a pointer into the given file name string.
583 * Return value: the name of the file without any leading directory components.
585 * Deprecated: Use g_path_get_basename() instead, but notice that
586 * g_path_get_basename() allocates new memory for the returned string, unlike
587 * this function which returns a pointer into the argument.
589 G_CONST_RETURN gchar*
590 g_basename (const gchar *file_name)
592 register gchar *base;
594 g_return_val_if_fail (file_name != NULL, NULL);
596 base = strrchr (file_name, G_DIR_SEPARATOR);
600 gchar *q = strrchr (file_name, '/');
601 if (base == NULL || (q != NULL && q > base))
610 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
611 return (gchar*) file_name + 2;
612 #endif /* G_OS_WIN32 */
614 return (gchar*) file_name;
618 * g_path_get_basename:
619 * @file_name: the name of the file.
621 * Gets the last component of the filename. If @file_name ends with a
622 * directory separator it gets the component before the last slash. If
623 * @file_name consists only of directory separators (and on Windows,
624 * possibly a drive letter), a single separator is returned. If
625 * @file_name is empty, it gets ".".
627 * Return value: a newly allocated string containing the last component of
631 g_path_get_basename (const gchar *file_name)
633 register gssize base;
634 register gssize last_nonslash;
638 g_return_val_if_fail (file_name != NULL, NULL);
640 if (file_name[0] == '\0')
642 return g_strdup (".");
644 last_nonslash = strlen (file_name) - 1;
646 while (last_nonslash >= 0 && G_IS_DIR_SEPARATOR (file_name [last_nonslash]))
649 if (last_nonslash == -1)
650 /* string only containing slashes */
651 return g_strdup (G_DIR_SEPARATOR_S);
654 if (last_nonslash == 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
655 /* string only containing slashes and a drive */
656 return g_strdup (G_DIR_SEPARATOR_S);
657 #endif /* G_OS_WIN32 */
659 base = last_nonslash;
661 while (base >=0 && !G_IS_DIR_SEPARATOR (file_name [base]))
665 if (base == -1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
667 #endif /* G_OS_WIN32 */
669 len = last_nonslash - base;
670 retval = g_malloc (len + 1);
671 memcpy (retval, file_name + base + 1, len);
677 * g_path_is_absolute:
678 * @file_name: a file name.
680 * Returns %TRUE if the given @file_name is an absolute file name,
681 * i.e. it contains a full path from the root directory such as "/usr/local"
682 * on UNIX or "C:\windows" on Windows systems.
684 * Returns: %TRUE if @file_name is an absolute path.
687 g_path_is_absolute (const gchar *file_name)
689 g_return_val_if_fail (file_name != NULL, FALSE);
691 if (G_IS_DIR_SEPARATOR (file_name[0]))
695 /* Recognize drive letter on native Windows */
696 if (g_ascii_isalpha (file_name[0]) &&
697 file_name[1] == ':' && G_IS_DIR_SEPARATOR (file_name[2]))
699 #endif /* G_OS_WIN32 */
706 * @file_name: a file name.
708 * Returns a pointer into @file_name after the root component, i.e. after
709 * the "/" in UNIX or "C:\" under Windows. If @file_name is not an absolute
710 * path it returns %NULL.
712 * Returns: a pointer into @file_name after the root component.
714 G_CONST_RETURN gchar*
715 g_path_skip_root (const gchar *file_name)
717 g_return_val_if_fail (file_name != NULL, NULL);
719 #ifdef G_PLATFORM_WIN32
720 /* Skip \\server\share or //server/share */
721 if (G_IS_DIR_SEPARATOR (file_name[0]) &&
722 G_IS_DIR_SEPARATOR (file_name[1]) &&
724 !G_IS_DIR_SEPARATOR (file_name[2]))
728 p = strchr (file_name + 2, G_DIR_SEPARATOR);
731 gchar *q = strchr (file_name + 2, '/');
732 if (p == NULL || (q != NULL && q < p))
742 while (file_name[0] && !G_IS_DIR_SEPARATOR (file_name[0]))
745 /* Possibly skip a backslash after the share name */
746 if (G_IS_DIR_SEPARATOR (file_name[0]))
749 return (gchar *)file_name;
754 /* Skip initial slashes */
755 if (G_IS_DIR_SEPARATOR (file_name[0]))
757 while (G_IS_DIR_SEPARATOR (file_name[0]))
759 return (gchar *)file_name;
764 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':' && G_IS_DIR_SEPARATOR (file_name[2]))
765 return (gchar *)file_name + 3;
772 * g_path_get_dirname:
773 * @file_name: the name of the file.
775 * Gets the directory components of a file name. If the file name has no
776 * directory components "." is returned. The returned string should be
777 * freed when no longer needed.
779 * Returns: the directory components of the file.
782 g_path_get_dirname (const gchar *file_name)
784 register gchar *base;
787 g_return_val_if_fail (file_name != NULL, NULL);
789 base = strrchr (file_name, G_DIR_SEPARATOR);
792 gchar *q = strrchr (file_name, '/');
793 if (base == NULL || (q != NULL && q > base))
800 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
802 gchar drive_colon_dot[4];
804 drive_colon_dot[0] = file_name[0];
805 drive_colon_dot[1] = ':';
806 drive_colon_dot[2] = '.';
807 drive_colon_dot[3] = '\0';
809 return g_strdup (drive_colon_dot);
812 return g_strdup (".");
815 while (base > file_name && G_IS_DIR_SEPARATOR (*base))
819 /* base points to the char before the last slash.
821 * In case file_name is the root of a drive (X:\) or a child of the
822 * root of a drive (X:\foo), include the slash.
824 * In case file_name is the root share of an UNC path
825 * (\\server\share), add a slash, returning \\server\share\ .
827 * In case file_name is a direct child of a share in an UNC path
828 * (\\server\share\foo), include the slash after the share name,
829 * returning \\server\share\ .
831 if (base == file_name + 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
833 else if (G_IS_DIR_SEPARATOR (file_name[0]) &&
834 G_IS_DIR_SEPARATOR (file_name[1]) &&
836 !G_IS_DIR_SEPARATOR (file_name[2]) &&
837 base >= file_name + 2)
839 const gchar *p = file_name + 2;
840 while (*p && !G_IS_DIR_SEPARATOR (*p))
844 len = (guint) strlen (file_name) + 1;
845 base = g_new (gchar, len + 1);
846 strcpy (base, file_name);
847 base[len-1] = G_DIR_SEPARATOR;
851 if (G_IS_DIR_SEPARATOR (*p))
854 while (*p && !G_IS_DIR_SEPARATOR (*p))
862 len = (guint) 1 + base - file_name;
864 base = g_new (gchar, len + 1);
865 g_memmove (base, file_name, len);
874 * Gets the current directory.
875 * The returned string should be freed when no longer needed. The encoding
876 * of the returned string is system defined. On Windows, it is always UTF-8.
878 * Returns: the current directory.
881 g_get_current_dir (void)
887 if (G_WIN32_HAVE_WIDECHAR_API ())
889 wchar_t dummy[2], *wdir;
892 len = GetCurrentDirectoryW (2, dummy);
893 wdir = g_new (wchar_t, len);
895 if (GetCurrentDirectoryW (len, wdir) == len - 1)
896 dir = g_utf16_to_utf8 (wdir, -1, NULL, NULL, NULL);
902 gchar dummy[2], *cpdir;
905 len = GetCurrentDirectoryA (2, dummy);
906 cpdir = g_new (gchar, len);
908 if (GetCurrentDirectoryA (len, cpdir) == len - 1)
909 dir = g_locale_to_utf8 (cpdir, -1, NULL, NULL, NULL);
915 dir = g_strdup ("\\");
921 gchar *buffer = NULL;
923 static gulong max_len = 0;
926 max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
928 /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
929 * and, if that wasn't bad enough, hangs in doing so.
931 #if (defined (sun) && !defined (__SVR4)) || !defined(HAVE_GETCWD)
932 buffer = g_new (gchar, max_len + 1);
934 dir = getwd (buffer);
935 #else /* !sun || !HAVE_GETCWD */
936 while (max_len < G_MAXULONG / 2)
938 buffer = g_new (gchar, max_len + 1);
940 dir = getcwd (buffer, max_len);
942 if (dir || errno != ERANGE)
948 #endif /* !sun || !HAVE_GETCWD */
950 if (!dir || !*buffer)
952 /* hm, should we g_error() out here?
953 * this can happen if e.g. "./" has mode \0000
955 buffer[0] = G_DIR_SEPARATOR;
959 dir = g_strdup (buffer);
968 * @variable: the environment variable to get, in the GLib file name encoding.
970 * Returns the value of an environment variable. The name and value
971 * are in the GLib file name encoding. On UNIX, this means the actual
972 * bytes which might or might not be in some consistent character set
973 * and encoding. On Windows, it is in UTF-8. On Windows, in case the
974 * environment variable's value contains references to other
975 * environment variables, they are expanded.
977 * Return value: the value of the environment variable, or %NULL if
978 * the environment variable is not found. The returned string may be
979 * overwritten by the next call to g_getenv(), g_setenv() or
982 G_CONST_RETURN gchar*
983 g_getenv (const gchar *variable)
987 g_return_val_if_fail (variable != NULL, NULL);
989 return getenv (variable);
991 #else /* G_OS_WIN32 */
996 g_return_val_if_fail (variable != NULL, NULL);
997 g_return_val_if_fail (g_utf8_validate (variable, -1, NULL), NULL);
999 /* On Windows NT, it is relatively typical that environment
1000 * variables contain references to other environment variables. If
1001 * so, use ExpandEnvironmentStrings(). (In an ideal world, such
1002 * environment variables would be stored in the Registry as
1003 * REG_EXPAND_SZ type values, and would then get automatically
1004 * expanded before a program sees them. But there is broken software
1005 * that stores environment variables as REG_SZ values even if they
1006 * contain references to other environment variables.)
1009 if (G_WIN32_HAVE_WIDECHAR_API ())
1011 wchar_t dummy[2], *wname, *wvalue;
1014 wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1016 len = GetEnvironmentVariableW (wname, dummy, 2);
1026 wvalue = g_new (wchar_t, len);
1028 if (GetEnvironmentVariableW (wname, wvalue, len) != len - 1)
1035 if (wcschr (wvalue, L'%') != NULL)
1037 wchar_t *tem = wvalue;
1039 len = ExpandEnvironmentStringsW (wvalue, dummy, 2);
1043 wvalue = g_new (wchar_t, len);
1045 if (ExpandEnvironmentStringsW (tem, wvalue, len) != len)
1055 value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
1062 gchar dummy[3], *cpname, *cpvalue;
1065 cpname = g_locale_from_utf8 (variable, -1, NULL, NULL, NULL);
1067 g_return_val_if_fail (cpname != NULL, NULL);
1069 len = GetEnvironmentVariableA (cpname, dummy, 2);
1079 cpvalue = g_new (gchar, len);
1081 if (GetEnvironmentVariableA (cpname, cpvalue, len) != len - 1)
1088 if (strchr (cpvalue, '%') != NULL)
1090 gchar *tem = cpvalue;
1092 len = ExpandEnvironmentStringsA (cpvalue, dummy, 3);
1096 cpvalue = g_new (gchar, len);
1098 if (ExpandEnvironmentStringsA (tem, cpvalue, len) != len)
1108 value = g_locale_to_utf8 (cpvalue, -1, NULL, NULL, NULL);
1114 quark = g_quark_from_string (value);
1117 return g_quark_to_string (quark);
1119 #endif /* G_OS_WIN32 */
1124 * @variable: the environment variable to set, must not contain '='.
1125 * @value: the value for to set the variable to.
1126 * @overwrite: whether to change the variable if it already exists.
1128 * Sets an environment variable. Both the variable's name and value
1129 * should be in the GLib file name encoding. On UNIX, this means that
1130 * they can be any sequence of bytes. On Windows, they should be in
1133 * Note that on some systems, when variables are overwritten, the memory
1134 * used for the previous variables and its value isn't reclaimed.
1136 * Returns: %FALSE if the environment variable couldn't be set.
1141 g_setenv (const gchar *variable,
1152 g_return_val_if_fail (variable != NULL, FALSE);
1153 g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
1156 result = setenv (variable, value, overwrite);
1158 if (!overwrite && getenv (variable) != NULL)
1161 /* This results in a leak when you overwrite existing
1162 * settings. It would be fairly easy to fix this by keeping
1163 * our own parallel array or hash table.
1165 string = g_strconcat (variable, "=", value, NULL);
1166 result = putenv (string);
1170 #else /* G_OS_WIN32 */
1174 g_return_val_if_fail (variable != NULL, FALSE);
1175 g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
1176 g_return_val_if_fail (g_utf8_validate (variable, -1, NULL), FALSE);
1177 g_return_val_if_fail (g_utf8_validate (value, -1, NULL), FALSE);
1179 if (!overwrite && g_getenv (variable) != NULL)
1182 /* We want to (if possible) set both the environment variable copy
1183 * kept by the C runtime and the one kept by the system.
1185 * We can't use only the C runtime's putenv or _wputenv() as that
1186 * won't work for arbitrary Unicode strings in a "non-Unicode" app
1187 * (with main() and not wmain()). In a "main()" app the C runtime
1188 * initializes the C runtime's environment table by converting the
1189 * real (wide char) environment variables to system codepage, thus
1190 * breaking those that aren't representable in the system codepage.
1192 * As the C runtime's putenv() will also set the system copy, we do
1193 * the putenv() first, then call SetEnvironmentValueW ourselves.
1196 if (G_WIN32_HAVE_WIDECHAR_API ())
1198 wchar_t *wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1199 wchar_t *wvalue = g_utf8_to_utf16 (value, -1, NULL, NULL, NULL);
1200 gchar *tem = g_strconcat (variable, "=", value, NULL);
1201 wchar_t *wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL);
1204 _wputenv (wassignment);
1205 g_free (wassignment);
1207 retval = (SetEnvironmentVariableW (wname, wvalue) != 0);
1214 /* In the non-Unicode case (Win9x), just putenv() is good
1217 gchar *tem = g_strconcat (variable, "=", value, NULL);
1218 gchar *cpassignment = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
1222 retval = (putenv (cpassignment) == 0);
1224 g_free (cpassignment);
1229 #endif /* G_OS_WIN32 */
1234 /* According to the Single Unix Specification, environ is not in
1235 * any system header, although unistd.h often declares it.
1237 extern char **environ;
1243 * @variable: the environment variable to remove, must not contain '='.
1245 * Removes an environment variable from the environment.
1247 * Note that on some systems, when variables are overwritten, the memory
1248 * used for the previous variables and its value isn't reclaimed.
1249 * Furthermore, this function can't be guaranteed to operate in a
1255 g_unsetenv (const gchar *variable)
1259 #ifdef HAVE_UNSETENV
1260 g_return_if_fail (variable != NULL);
1261 g_return_if_fail (strchr (variable, '=') == NULL);
1263 unsetenv (variable);
1264 #else /* !HAVE_UNSETENV */
1268 g_return_if_fail (variable != NULL);
1269 g_return_if_fail (strchr (variable, '=') == NULL);
1271 len = strlen (variable);
1273 /* Mess directly with the environ array.
1274 * This seems to be the only portable way to do this.
1276 * Note that we remove *all* environment entries for
1277 * the variable name, not just the first.
1282 if (strncmp (*e, variable, len) != 0 || (*e)[len] != '=')
1290 #endif /* !HAVE_UNSETENV */
1292 #else /* G_OS_WIN32 */
1294 g_return_if_fail (variable != NULL);
1295 g_return_if_fail (strchr (variable, '=') == NULL);
1296 g_return_if_fail (g_utf8_validate (variable, -1, NULL));
1298 if (G_WIN32_HAVE_WIDECHAR_API ())
1300 wchar_t *wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1301 gchar *tem = g_strconcat (variable, "=", NULL);
1302 wchar_t *wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL);
1305 _wputenv (wassignment);
1306 g_free (wassignment);
1308 SetEnvironmentVariableW (wname, NULL);
1314 /* In the non-Unicode case (Win9x), just putenv() is good
1317 gchar *tem = g_strconcat (variable, "=", NULL);
1318 gchar *cpassignment = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
1322 putenv (cpassignment);
1324 g_free (cpassignment);
1327 #endif /* G_OS_WIN32 */
1333 * Gets the names of all variables set in the environment.
1335 * Returns: a %NULL-terminated list of strings which must be freed
1336 * with g_strfreev().
1343 gchar **result, *eq;
1346 len = g_strv_length (environ);
1347 result = g_new0 (gchar *, len + 1);
1350 for (i = 0; i < len; i++)
1352 eq = strchr (environ[i], '=');
1354 result[j++] = g_strndup (environ[i], eq - environ[i]);
1362 G_LOCK_DEFINE_STATIC (g_utils_global);
1364 static gchar *g_tmp_dir = NULL;
1365 static gchar *g_user_name = NULL;
1366 static gchar *g_real_name = NULL;
1367 static gchar *g_home_dir = NULL;
1368 static gchar *g_host_name = NULL;
1371 /* System codepage versions of the above, kept at file level so that they,
1372 * too, are produced only once.
1374 static gchar *g_tmp_dir_cp = NULL;
1375 static gchar *g_user_name_cp = NULL;
1376 static gchar *g_real_name_cp = NULL;
1377 static gchar *g_home_dir_cp = NULL;
1380 static gchar *g_user_data_dir = NULL;
1381 static gchar **g_system_data_dirs = NULL;
1382 static gchar *g_user_cache_dir = NULL;
1383 static gchar *g_user_config_dir = NULL;
1384 static gchar **g_system_config_dirs = NULL;
1389 get_special_folder (int csidl)
1393 wchar_t wc[MAX_PATH+1];
1396 LPITEMIDLIST pidl = NULL;
1398 gchar *retval = NULL;
1400 hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl);
1403 if (G_WIN32_HAVE_WIDECHAR_API ())
1405 b = SHGetPathFromIDListW (pidl, path.wc);
1407 retval = g_utf16_to_utf8 (path.wc, -1, NULL, NULL, NULL);
1411 b = SHGetPathFromIDListA (pidl, path.c);
1413 retval = g_locale_to_utf8 (path.c, -1, NULL, NULL, NULL);
1415 CoTaskMemFree (pidl);
1421 get_windows_directory_root (void)
1423 char windowsdir[MAX_PATH];
1425 if (GetWindowsDirectory (windowsdir, sizeof (windowsdir)))
1427 /* Usually X:\Windows, but in terminal server environments
1428 * might be an UNC path, AFAIK.
1430 char *p = (char *) g_path_skip_root (windowsdir);
1431 if (G_IS_DIR_SEPARATOR (p[-1]) && p[-2] != ':')
1434 return g_strdup (windowsdir);
1437 return g_strdup ("C:\\");
1442 /* HOLDS: g_utils_global_lock */
1444 g_get_any_init (void)
1448 gchar hostname[100];
1450 g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
1452 g_tmp_dir = g_strdup (g_getenv ("TMP"));
1454 g_tmp_dir = g_strdup (g_getenv ("TEMP"));
1458 g_tmp_dir = get_windows_directory_root ();
1464 g_tmp_dir = g_strdup (P_tmpdir);
1465 k = strlen (g_tmp_dir);
1466 if (k > 1 && G_IS_DIR_SEPARATOR (g_tmp_dir[k - 1]))
1467 g_tmp_dir[k - 1] = '\0';
1473 g_tmp_dir = g_strdup ("/tmp");
1475 #endif /* !G_OS_WIN32 */
1478 /* We check $HOME first for Win32, though it is a last resort for Unix
1479 * where we prefer the results of getpwuid().
1481 g_home_dir = g_strdup (g_getenv ("HOME"));
1483 /* Only believe HOME if it is an absolute path and exists */
1486 if (!(g_path_is_absolute (g_home_dir) &&
1487 g_file_test (g_home_dir, G_FILE_TEST_IS_DIR)))
1489 g_free (g_home_dir);
1494 /* In case HOME is Unix-style (it happens), convert it to
1500 while ((p = strchr (g_home_dir, '/')) != NULL)
1506 /* USERPROFILE is probably the closest equivalent to $HOME? */
1507 if (g_getenv ("USERPROFILE") != NULL)
1508 g_home_dir = g_strdup (g_getenv ("USERPROFILE"));
1512 g_home_dir = get_special_folder (CSIDL_PROFILE);
1515 g_home_dir = get_windows_directory_root ();
1516 #endif /* G_OS_WIN32 */
1520 struct passwd *pw = NULL;
1521 gpointer buffer = NULL;
1524 # if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R)
1526 # ifdef _SC_GETPW_R_SIZE_MAX
1527 /* This reurns the maximum length */
1528 glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
1532 # else /* _SC_GETPW_R_SIZE_MAX */
1534 # endif /* _SC_GETPW_R_SIZE_MAX */
1539 /* we allocate 6 extra bytes to work around a bug in
1540 * Mac OS < 10.3. See #156446
1542 buffer = g_malloc (bufsize + 6);
1545 # ifdef HAVE_POSIX_GETPWUID_R
1546 error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
1547 error = error < 0 ? errno : error;
1548 # else /* HAVE_NONPOSIX_GETPWUID_R */
1549 /* HPUX 11 falls into the HAVE_POSIX_GETPWUID_R case */
1550 # if defined(_AIX) || defined(__hpux)
1551 error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1552 pw = error == 0 ? &pwd : NULL;
1554 pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1555 error = pw ? 0 : errno;
1557 # endif /* HAVE_NONPOSIX_GETPWUID_R */
1561 /* we bail out prematurely if the user id can't be found
1562 * (should be pretty rare case actually), or if the buffer
1563 * should be sufficiently big and lookups are still not
1566 if (error == 0 || error == ENOENT)
1568 g_warning ("getpwuid_r(): failed due to unknown user id (%lu)",
1569 (gulong) getuid ());
1572 if (bufsize > 32 * 1024)
1574 g_warning ("getpwuid_r(): failed due to: %s.",
1575 g_strerror (error));
1583 # endif /* HAVE_POSIX_GETPWUID_R || HAVE_NONPOSIX_GETPWUID_R */
1588 pw = getpwuid (getuid ());
1593 g_user_name = g_strdup (pw->pw_name);
1595 if (pw->pw_gecos && *pw->pw_gecos != '\0')
1597 gchar **gecos_fields;
1600 /* split the gecos field and substitute '&' */
1601 gecos_fields = g_strsplit (pw->pw_gecos, ",", 0);
1602 name_parts = g_strsplit (gecos_fields[0], "&", 0);
1603 pw->pw_name[0] = g_ascii_toupper (pw->pw_name[0]);
1604 g_real_name = g_strjoinv (pw->pw_name, name_parts);
1605 g_strfreev (gecos_fields);
1606 g_strfreev (name_parts);
1610 g_home_dir = g_strdup (pw->pw_dir);
1615 #else /* !HAVE_PWD_H */
1618 if (G_WIN32_HAVE_WIDECHAR_API ())
1620 guint len = UNLEN+1;
1621 wchar_t buffer[UNLEN+1];
1623 if (GetUserNameW (buffer, (LPDWORD) &len))
1625 g_user_name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
1626 g_real_name = g_strdup (g_user_name);
1631 guint len = UNLEN+1;
1632 char buffer[UNLEN+1];
1634 if (GetUserNameA (buffer, (LPDWORD) &len))
1636 g_user_name = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
1637 g_real_name = g_strdup (g_user_name);
1640 #endif /* G_OS_WIN32 */
1642 #endif /* !HAVE_PWD_H */
1646 g_home_dir = g_strdup (g_getenv ("HOME"));
1650 /* change '\\' in %HOME% to '/' */
1651 g_strdelimit (g_home_dir, "\\",'/');
1654 g_user_name = g_strdup ("somebody");
1656 g_real_name = g_strdup ("Unknown");
1659 if (gethostname (hostname, sizeof (hostname)) == -1)
1660 g_host_name = g_strdup ("unknown");
1662 g_host_name = g_strdup (hostname);
1665 DWORD size = sizeof (hostname);
1667 if (!GetComputerName (hostname, &size))
1668 g_host_name = g_strdup ("unknown");
1670 g_host_name = g_strdup (hostname);
1675 g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
1676 g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
1677 g_real_name_cp = g_locale_from_utf8 (g_real_name, -1, NULL, NULL, NULL);
1680 g_tmp_dir_cp = g_strdup ("\\");
1681 if (!g_user_name_cp)
1682 g_user_name_cp = g_strdup ("somebody");
1683 if (!g_real_name_cp)
1684 g_real_name_cp = g_strdup ("Unknown");
1686 /* home_dir might be NULL, unlike tmp_dir, user_name and
1690 g_home_dir_cp = g_locale_from_utf8 (g_home_dir, -1, NULL, NULL, NULL);
1692 g_home_dir_cp = NULL;
1693 #endif /* G_OS_WIN32 */
1700 * Gets the user name of the current user. The encoding of the returned
1701 * string is system-defined. On UNIX, it might be the preferred file name
1702 * encoding, or something else, and there is no guarantee that it is even
1703 * consistent on a machine. On Windows, it is always UTF-8.
1705 * Returns: the user name of the current user.
1707 G_CONST_RETURN gchar*
1708 g_get_user_name (void)
1710 G_LOCK (g_utils_global);
1713 G_UNLOCK (g_utils_global);
1721 * Gets the real name of the user. This usually comes from the user's entry
1722 * in the <filename>passwd</filename> file. The encoding of the returned
1723 * string is system-defined. (On Windows, it is, however, always UTF-8.)
1724 * If the real user name cannot be determined, the string "Unknown" is
1727 * Returns: the user's real name.
1729 G_CONST_RETURN gchar*
1730 g_get_real_name (void)
1732 G_LOCK (g_utils_global);
1735 G_UNLOCK (g_utils_global);
1743 * Gets the current user's home directory.
1745 * Note that in contrast to traditional UNIX tools, this function
1746 * prefers <filename>passwd</filename> entries over the <envar>HOME</envar>
1747 * environment variable.
1749 * Returns: the current user's home directory.
1751 G_CONST_RETURN gchar*
1752 g_get_home_dir (void)
1754 G_LOCK (g_utils_global);
1757 G_UNLOCK (g_utils_global);
1765 * Gets the directory to use for temporary files. This is found from
1766 * inspecting the environment variables <envar>TMPDIR</envar>,
1767 * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none
1768 * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
1769 * The encoding of the returned string is system-defined. On Windows,
1770 * it is always UTF-8. The return value is never %NULL.
1772 * Returns: the directory to use for temporary files.
1774 G_CONST_RETURN gchar*
1775 g_get_tmp_dir (void)
1777 G_LOCK (g_utils_global);
1780 G_UNLOCK (g_utils_global);
1788 * Return a name for the machine.
1790 * The returned name is not necessarily a fully-qualified domain name,
1791 * or even present in DNS or some other name service at all. It need
1792 * not even be unique on your local network or site, but usually it
1793 * is. Callers should not rely on the return value having any specific
1794 * properties like uniqueness for security purposes. Even if the name
1795 * of the machine is changed while an application is running, the
1796 * return value from this function does not change. The returned
1797 * string is owned by GLib and should not be modified or freed. If no
1798 * name can be determined, a default fixed string "unknown" is
1801 * Returns: the host name of the machine.
1806 g_get_host_name (void)
1808 G_LOCK (g_utils_global);
1811 G_UNLOCK (g_utils_global);
1816 G_LOCK_DEFINE_STATIC (g_prgname);
1817 static gchar *g_prgname = NULL;
1822 * Gets the name of the program. This name should <emphasis>not</emphasis>
1823 * be localized, contrast with g_get_application_name().
1824 * (If you are using GDK or GTK+ the program name is set in gdk_init(),
1825 * which is called by gtk_init(). The program name is found by taking
1826 * the last component of <literal>argv[0]</literal>.)
1828 * Returns: the name of the program. The returned string belongs
1829 * to GLib and must not be modified or freed.
1832 g_get_prgname (void)
1838 if (g_prgname == NULL)
1840 static gboolean beenhere = FALSE;
1844 gchar *utf8_buf = NULL;
1847 if (G_WIN32_HAVE_WIDECHAR_API ())
1849 wchar_t buf[MAX_PATH+1];
1850 if (GetModuleFileNameW (GetModuleHandle (NULL),
1851 buf, G_N_ELEMENTS (buf)) > 0)
1852 utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL);
1856 gchar buf[MAX_PATH+1];
1857 if (GetModuleFileNameA (GetModuleHandle (NULL),
1858 buf, G_N_ELEMENTS (buf)) > 0)
1859 utf8_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
1863 g_prgname = g_path_get_basename (utf8_buf);
1870 G_UNLOCK (g_prgname);
1877 * @prgname: the name of the program.
1879 * Sets the name of the program. This name should <emphasis>not</emphasis>
1880 * be localized, contrast with g_set_application_name(). Note that for
1881 * thread-safety reasons this function can only be called once.
1884 g_set_prgname (const gchar *prgname)
1888 g_prgname = g_strdup (prgname);
1889 G_UNLOCK (g_prgname);
1892 G_LOCK_DEFINE_STATIC (g_application_name);
1893 static gchar *g_application_name = NULL;
1896 * g_get_application_name:
1898 * Gets a human-readable name for the application, as set by
1899 * g_set_application_name(). This name should be localized if
1900 * possible, and is intended for display to the user. Contrast with
1901 * g_get_prgname(), which gets a non-localized name. If
1902 * g_set_application_name() has not been called, returns the result of
1903 * g_get_prgname() (which may be %NULL if g_set_prgname() has also not
1906 * Return value: human-readable application name. may return %NULL
1910 G_CONST_RETURN gchar*
1911 g_get_application_name (void)
1915 G_LOCK (g_application_name);
1916 retval = g_application_name;
1917 G_UNLOCK (g_application_name);
1920 return g_get_prgname ();
1926 * g_set_application_name:
1927 * @application_name: localized name of the application
1929 * Sets a human-readable name for the application. This name should be
1930 * localized if possible, and is intended for display to the user.
1931 * Contrast with g_set_prgname(), which sets a non-localized name.
1932 * g_set_prgname() will be called automatically by gtk_init(),
1933 * but g_set_application_name() will not.
1935 * Note that for thread safety reasons, this function can only
1938 * The application name will be used in contexts such as error messages,
1939 * or when displaying an application's name in the task list.
1943 g_set_application_name (const gchar *application_name)
1945 gboolean already_set = FALSE;
1947 G_LOCK (g_application_name);
1948 if (g_application_name)
1951 g_application_name = g_strdup (application_name);
1952 G_UNLOCK (g_application_name);
1955 g_warning ("g_set_application() name called multiple times");
1959 * g_get_user_data_dir:
1961 * Returns a base directory in which to access application data such
1962 * as icons that is customized for a particular user.
1964 * On UNIX platforms this is determined using the mechanisms described in
1965 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
1966 * XDG Base Directory Specification</ulink>
1968 * Return value: a string owned by GLib that must not be modified
1972 G_CONST_RETURN gchar*
1973 g_get_user_data_dir (void)
1977 G_LOCK (g_utils_global);
1979 if (!g_user_data_dir)
1982 data_dir = get_special_folder (CSIDL_PERSONAL);
1984 data_dir = (gchar *) g_getenv ("XDG_DATA_HOME");
1986 if (data_dir && data_dir[0])
1987 data_dir = g_strdup (data_dir);
1989 if (!data_dir || !data_dir[0])
1995 data_dir = g_build_filename (g_home_dir, ".local",
1998 data_dir = g_build_filename (g_tmp_dir, g_user_name, ".local",
2002 g_user_data_dir = data_dir;
2005 data_dir = g_user_data_dir;
2007 G_UNLOCK (g_utils_global);
2013 * g_get_user_config_dir:
2015 * Returns a base directory in which to store user-specific application
2016 * configuration information such as user preferences and settings.
2018 * On UNIX platforms this is determined using the mechanisms described in
2019 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2020 * XDG Base Directory Specification</ulink>
2022 * Return value: a string owned by GLib that must not be modified
2026 G_CONST_RETURN gchar*
2027 g_get_user_config_dir (void)
2031 G_LOCK (g_utils_global);
2033 if (!g_user_config_dir)
2036 config_dir = get_special_folder (CSIDL_APPDATA);
2038 config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME");
2040 if (config_dir && config_dir[0])
2041 config_dir = g_strdup (config_dir);
2043 if (!config_dir || !config_dir[0])
2049 config_dir = g_build_filename (g_home_dir, ".config", NULL);
2051 config_dir = g_build_filename (g_tmp_dir, g_user_name, ".config", NULL);
2053 g_user_config_dir = config_dir;
2056 config_dir = g_user_config_dir;
2058 G_UNLOCK (g_utils_global);
2064 * g_get_user_cache_dir:
2066 * Returns a base directory in which to store non-essential, cached
2067 * data specific to particular user.
2069 * On UNIX platforms this is determined using the mechanisms described in
2070 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2071 * XDG Base Directory Specification</ulink>
2073 * Return value: a string owned by GLib that must not be modified
2077 G_CONST_RETURN gchar*
2078 g_get_user_cache_dir (void)
2082 G_LOCK (g_utils_global);
2084 if (!g_user_cache_dir)
2087 cache_dir = get_special_folder (CSIDL_INTERNET_CACHE); /* XXX correct? */
2089 cache_dir = (gchar *) g_getenv ("XDG_CACHE_HOME");
2091 if (cache_dir && cache_dir[0])
2092 cache_dir = g_strdup (cache_dir);
2094 if (!cache_dir || !cache_dir[0])
2100 cache_dir = g_build_filename (g_home_dir, ".cache", NULL);
2102 cache_dir = g_build_filename (g_tmp_dir, g_user_name, ".cache", NULL);
2104 g_user_cache_dir = cache_dir;
2107 cache_dir = g_user_cache_dir;
2109 G_UNLOCK (g_utils_global);
2116 #undef g_get_system_data_dirs
2119 get_module_for_address (gconstpointer address)
2121 /* Holds the g_utils_global lock */
2123 static gboolean beenhere = FALSE;
2124 typedef BOOL (WINAPI *t_GetModuleHandleExA) (DWORD, LPCTSTR, HMODULE *);
2125 static t_GetModuleHandleExA p_GetModuleHandleExA = NULL;
2133 p_GetModuleHandleExA =
2134 (t_GetModuleHandleExA) GetProcAddress (LoadLibrary ("kernel32.dll"),
2135 "GetModuleHandleExA");
2139 if (p_GetModuleHandleExA == NULL ||
2140 !(*p_GetModuleHandleExA) (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
2141 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
2144 MEMORY_BASIC_INFORMATION mbi;
2145 VirtualQuery (address, &mbi, sizeof (mbi));
2146 hmodule = (HMODULE) mbi.AllocationBase;
2153 get_module_share_dir (gconstpointer address)
2156 gchar *filename = NULL;
2159 hmodule = get_module_for_address (address);
2160 if (hmodule == NULL)
2163 if (G_WIN32_IS_NT_BASED ())
2165 wchar_t wfilename[MAX_PATH];
2166 if (GetModuleFileNameW (hmodule, wfilename, G_N_ELEMENTS (wfilename)))
2167 filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
2171 char cpfilename[MAX_PATH];
2172 if (GetModuleFileNameA (hmodule, cpfilename, G_N_ELEMENTS (cpfilename)))
2173 filename = g_locale_to_utf8 (cpfilename, -1, NULL, NULL, NULL);
2176 if (filename == NULL)
2179 if ((p = strrchr (filename, G_DIR_SEPARATOR)) != NULL)
2182 p = strrchr (filename, G_DIR_SEPARATOR);
2183 if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
2186 retval = g_build_filename (filename, "share", NULL);
2192 G_CONST_RETURN gchar * G_CONST_RETURN *
2193 g_win32_get_system_data_dirs_for_module (gconstpointer address)
2197 static GHashTable *per_module_data_dirs = NULL;
2203 G_LOCK (g_utils_global);
2204 hmodule = get_module_for_address (address);
2205 if (hmodule != NULL)
2207 if (per_module_data_dirs == NULL)
2208 per_module_data_dirs = g_hash_table_new (NULL, NULL);
2211 retval = g_hash_table_lookup (per_module_data_dirs, hmodule);
2215 G_UNLOCK (g_utils_global);
2216 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2222 data_dirs = g_array_new (TRUE, TRUE, sizeof (char *));
2224 /* Documents and Settings\All Users\Application Data */
2225 p = get_special_folder (CSIDL_COMMON_APPDATA);
2227 g_array_append_val (data_dirs, p);
2229 /* Documents and Settings\All Users\Documents */
2230 p = get_special_folder (CSIDL_COMMON_DOCUMENTS);
2232 g_array_append_val (data_dirs, p);
2234 /* Using the above subfolders of Documents and Settings perhaps
2235 * makes sense from a Windows perspective.
2237 * But looking at the actual use cases of this function in GTK+
2238 * and GNOME software, what we really want is the "share"
2239 * subdirectory of the installation directory for the package
2240 * our caller is a part of.
2242 * The address parameter, if non-NULL, points to a function in the
2243 * calling module. Use that to determine that module's installation
2244 * folder, and use its "share" subfolder.
2246 * Additionally, also use the "share" subfolder of the installation
2247 * locations of GLib and the .exe file being run.
2249 * To guard against none of the above being what is really wanted,
2250 * callers of this function should have Win32-specific code to look
2251 * up their installation folder themselves, and handle a subfolder
2252 * "share" of it in the same way as the folders returned from this
2256 p = get_module_share_dir (address);
2258 g_array_append_val (data_dirs, p);
2260 p = g_win32_get_package_installation_subdirectory (NULL, dll_name, "share");
2262 g_array_append_val (data_dirs, p);
2264 p = g_win32_get_package_installation_subdirectory (NULL, NULL, "share");
2266 g_array_append_val (data_dirs, p);
2268 retval = (gchar **) g_array_free (data_dirs, FALSE);
2272 if (hmodule != NULL)
2273 g_hash_table_insert (per_module_data_dirs, hmodule, retval);
2274 G_UNLOCK (g_utils_global);
2277 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2283 * g_get_system_data_dirs:
2285 * Returns an ordered list of base directories in which to access
2286 * system-wide application data.
2288 * On UNIX platforms this is determined using the mechanisms described in
2289 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2290 * XDG Base Directory Specification</ulink>
2292 * On Windows the first elements in the list are the Application Data
2293 * and Documents folders for All Users. (These can be determined only
2294 * on Windows 2000 or later and are not present in the list on other
2295 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
2296 * CSIDL_COMMON_DOCUMENTS.
2298 * Then follows the "share" subfolder in the installation folder for
2299 * the package containing the DLL that calls this function, if it can
2302 * Finally the list contains the "share" subfolder in the installation
2303 * folder for GLib, and in the installation folder for the package the
2304 * application's .exe file belongs to.
2306 * The installation folders above are determined by looking up the
2307 * folder where the module (DLL or EXE) in question is located. If the
2308 * folder's name is "bin", its parent is used, otherwise the folder
2311 * Note that on Windows the returned list can vary depending on where
2312 * this function is called.
2314 * Return value: a %NULL-terminated array of strings owned by GLib that must
2315 * not be modified or freed.
2318 G_CONST_RETURN gchar * G_CONST_RETURN *
2319 g_get_system_data_dirs (void)
2321 gchar **data_dir_vector;
2323 G_LOCK (g_utils_global);
2325 if (!g_system_data_dirs)
2328 data_dir_vector = (gchar **) g_win32_get_system_data_dirs_for_module (NULL);
2330 gchar *data_dirs = (gchar *) g_getenv ("XDG_DATA_DIRS");
2332 if (!data_dirs || !data_dirs[0])
2333 data_dirs = "/usr/local/share/:/usr/share/";
2335 data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2338 g_system_data_dirs = data_dir_vector;
2341 data_dir_vector = g_system_data_dirs;
2343 G_UNLOCK (g_utils_global);
2345 return (G_CONST_RETURN gchar * G_CONST_RETURN *) data_dir_vector;
2349 * g_get_system_config_dirs:
2351 * Returns an ordered list of base directories in which to access
2352 * system-wide configuration information.
2354 * On UNIX platforms this is determined using the mechanisms described in
2355 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2356 * XDG Base Directory Specification</ulink>
2358 * Return value: a %NULL-terminated array of strings owned by GLib that must
2359 * not be modified or freed.
2362 G_CONST_RETURN gchar * G_CONST_RETURN *
2363 g_get_system_config_dirs (void)
2365 gchar *conf_dirs, **conf_dir_vector;
2367 G_LOCK (g_utils_global);
2369 if (!g_system_config_dirs)
2372 conf_dirs = get_special_folder (CSIDL_COMMON_APPDATA);
2375 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2380 /* Return empty list */
2381 conf_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0);
2384 conf_dirs = (gchar *) g_getenv ("XDG_CONFIG_DIRS");
2386 if (!conf_dirs || !conf_dirs[0])
2387 conf_dirs = "/etc/xdg";
2389 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2392 g_system_config_dirs = conf_dir_vector;
2395 conf_dir_vector = g_system_config_dirs;
2396 G_UNLOCK (g_utils_global);
2398 return (G_CONST_RETURN gchar * G_CONST_RETURN *) conf_dir_vector;
2403 static GHashTable *alias_table = NULL;
2405 /* read an alias file for the locales */
2407 read_aliases (gchar *file)
2413 alias_table = g_hash_table_new (g_str_hash, g_str_equal);
2414 fp = fopen (file,"r");
2417 while (fgets (buf, 256, fp))
2423 /* Line is a comment */
2424 if ((buf[0] == '#') || (buf[0] == '\0'))
2427 /* Reads first column */
2428 for (p = buf, q = NULL; *p; p++) {
2429 if ((*p == '\t') || (*p == ' ') || (*p == ':')) {
2432 while ((*q == '\t') || (*q == ' ')) {
2438 /* The line only had one column */
2439 if (!q || *q == '\0')
2442 /* Read second column */
2443 for (p = q; *p; p++) {
2444 if ((*p == '\t') || (*p == ' ')) {
2450 /* Add to alias table if necessary */
2451 if (!g_hash_table_lookup (alias_table, buf)) {
2452 g_hash_table_insert (alias_table, g_strdup (buf), g_strdup (q));
2461 unalias_lang (char *lang)
2468 read_aliases ("/usr/share/locale/locale.alias");
2471 while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0))
2476 static gboolean said_before = FALSE;
2478 g_warning ("Too many alias levels for a locale, "
2479 "may indicate a loop");
2488 /* Mask for components of locale spec. The ordering here is from
2489 * least significant to most significant
2493 COMPONENT_CODESET = 1 << 0,
2494 COMPONENT_TERRITORY = 1 << 1,
2495 COMPONENT_MODIFIER = 1 << 2
2498 /* Break an X/Open style locale specification into components
2501 explode_locale (const gchar *locale,
2507 const gchar *uscore_pos;
2508 const gchar *at_pos;
2509 const gchar *dot_pos;
2513 uscore_pos = strchr (locale, '_');
2514 dot_pos = strchr (uscore_pos ? uscore_pos : locale, '.');
2515 at_pos = strchr (dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@');
2519 mask |= COMPONENT_MODIFIER;
2520 *modifier = g_strdup (at_pos);
2523 at_pos = locale + strlen (locale);
2527 mask |= COMPONENT_CODESET;
2528 *codeset = g_strndup (dot_pos, at_pos - dot_pos);
2535 mask |= COMPONENT_TERRITORY;
2536 *territory = g_strndup (uscore_pos, dot_pos - uscore_pos);
2539 uscore_pos = dot_pos;
2541 *language = g_strndup (locale, uscore_pos - locale);
2547 * Compute all interesting variants for a given locale name -
2548 * by stripping off different components of the value.
2550 * For simplicity, we assume that the locale is in
2551 * X/Open format: language[_territory][.codeset][@modifier]
2553 * TODO: Extend this to handle the CEN format (see the GNUlibc docs)
2554 * as well. We could just copy the code from glibc wholesale
2555 * but it is big, ugly, and complicated, so I'm reluctant
2556 * to do so when this should handle 99% of the time...
2559 _g_compute_locale_variants (const gchar *locale)
2561 GSList *retval = NULL;
2563 gchar *language = NULL;
2564 gchar *territory = NULL;
2565 gchar *codeset = NULL;
2566 gchar *modifier = NULL;
2571 g_return_val_if_fail (locale != NULL, NULL);
2573 mask = explode_locale (locale, &language, &territory, &codeset, &modifier);
2575 /* Iterate through all possible combinations, from least attractive
2576 * to most attractive.
2578 for (i = 0; i <= mask; i++)
2579 if ((i & ~mask) == 0)
2581 gchar *val = g_strconcat (language,
2582 (i & COMPONENT_TERRITORY) ? territory : "",
2583 (i & COMPONENT_CODESET) ? codeset : "",
2584 (i & COMPONENT_MODIFIER) ? modifier : "",
2586 retval = g_slist_prepend (retval, val);
2590 if (mask & COMPONENT_CODESET)
2592 if (mask & COMPONENT_TERRITORY)
2594 if (mask & COMPONENT_MODIFIER)
2600 /* The following is (partly) taken from the gettext package.
2601 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */
2603 static const gchar *
2604 guess_category_value (const gchar *category_name)
2606 const gchar *retval;
2608 /* The highest priority value is the `LANGUAGE' environment
2609 variable. This is a GNU extension. */
2610 retval = g_getenv ("LANGUAGE");
2611 if ((retval != NULL) && (retval[0] != '\0'))
2614 /* `LANGUAGE' is not set. So we have to proceed with the POSIX
2615 methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some
2616 systems this can be done by the `setlocale' function itself. */
2618 /* Setting of LC_ALL overwrites all other. */
2619 retval = g_getenv ("LC_ALL");
2620 if ((retval != NULL) && (retval[0] != '\0'))
2623 /* Next comes the name of the desired category. */
2624 retval = g_getenv (category_name);
2625 if ((retval != NULL) && (retval[0] != '\0'))
2628 /* Last possibility is the LANG environment variable. */
2629 retval = g_getenv ("LANG");
2630 if ((retval != NULL) && (retval[0] != '\0'))
2633 #ifdef G_PLATFORM_WIN32
2634 /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and
2635 * LANG, which we already did above. Oh well. The main point of
2636 * calling g_win32_getlocale() is to get the thread's locale as used
2637 * by Windows and the Microsoft C runtime (in the "English_United
2638 * States" format) translated into the Unixish format.
2640 retval = g_win32_getlocale ();
2641 if ((retval != NULL) && (retval[0] != '\0'))
2648 typedef struct _GLanguageNamesCache GLanguageNamesCache;
2650 struct _GLanguageNamesCache {
2652 gchar **language_names;
2656 language_names_cache_free (gpointer data)
2658 GLanguageNamesCache *cache = data;
2659 g_free (cache->languages);
2660 g_strfreev (cache->language_names);
2665 * g_get_language_names:
2667 * Computes a list of applicable locale names, which can be used to
2668 * e.g. construct locale-dependent filenames or search paths. The returned
2669 * list is sorted from most desirable to least desirable and always contains
2670 * the default locale "C".
2672 * For example, if LANGUAGE=de:en_US, then the returned list is
2673 * "de", "en_US", "en", "C".
2675 * This function consults the environment variables <envar>LANGUAGE</envar>,
2676 * <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar>
2677 * to find the list of locales specified by the user.
2679 * Return value: a %NULL-terminated array of strings owned by GLib
2680 * that must not be modified or freed.
2684 G_CONST_RETURN gchar * G_CONST_RETURN *
2685 g_get_language_names (void)
2687 static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT;
2688 GLanguageNamesCache *cache = g_static_private_get (&cache_private);
2693 cache = g_new0 (GLanguageNamesCache, 1);
2694 g_static_private_set (&cache_private, cache, language_names_cache_free);
2697 value = guess_category_value ("LC_MESSAGES");
2701 if (!(cache->languages && strcmp (cache->languages, value) == 0))
2708 g_free (cache->languages);
2709 g_strfreev (cache->language_names);
2710 cache->languages = g_strdup (value);
2712 alist = g_strsplit (value, ":", 0);
2714 for (a = alist; *a; a++)
2716 gchar *b = unalias_lang (*a);
2717 list = g_slist_concat (list, _g_compute_locale_variants (b));
2720 list = g_slist_append (list, g_strdup ("C"));
2722 cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1);
2723 for (l = list, i = 0; l; l = l->next, i++)
2724 languages[i] = l->data;
2725 languages[i] = NULL;
2727 g_slist_free (list);
2730 return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names;
2735 * @v: a #gpointer key
2737 * Converts a gpointer to a hash value.
2738 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2739 * when using pointers as keys in a #GHashTable.
2741 * Returns: a hash value corresponding to the key.
2744 g_direct_hash (gconstpointer v)
2746 return GPOINTER_TO_UINT (v);
2752 * @v2: a key to compare with @v1.
2754 * Compares two #gpointer arguments and returns %TRUE if they are equal.
2755 * It can be passed to g_hash_table_new() as the @key_equal_func
2756 * parameter, when using pointers as keys in a #GHashTable.
2758 * Returns: %TRUE if the two keys match.
2761 g_direct_equal (gconstpointer v1,
2769 * @v1: a pointer to a #gint key.
2770 * @v2: a pointer to a #gint key to compare with @v1.
2772 * Compares the two #gint values being pointed to and returns
2773 * %TRUE if they are equal.
2774 * It can be passed to g_hash_table_new() as the @key_equal_func
2775 * parameter, when using pointers to integers as keys in a #GHashTable.
2777 * Returns: %TRUE if the two keys match.
2780 g_int_equal (gconstpointer v1,
2783 return *((const gint*) v1) == *((const gint*) v2);
2788 * @v: a pointer to a #gint key
2790 * Converts a pointer to a #gint to a hash value.
2791 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2792 * when using pointers to integers values as keys in a #GHashTable.
2794 * Returns: a hash value corresponding to the key.
2797 g_int_hash (gconstpointer v)
2799 return *(const gint*) v;
2803 * g_nullify_pointer:
2804 * @nullify_location: the memory address of the pointer.
2806 * Set the pointer at the specified location to %NULL.
2809 g_nullify_pointer (gpointer *nullify_location)
2811 g_return_if_fail (nullify_location != NULL);
2813 *nullify_location = NULL;
2819 * Get the codeset for the current locale.
2821 * Return value: a newly allocated string containing the name
2822 * of the codeset. This string must be freed with g_free().
2825 g_get_codeset (void)
2827 const gchar *charset;
2829 g_get_charset (&charset);
2831 return g_strdup (charset);
2834 /* This is called from g_thread_init(). It's used to
2835 * initialize some static data in a threadsafe way.
2838 _g_utils_thread_init (void)
2840 g_get_language_names ();
2845 #include <libintl.h>
2850 * _glib_get_locale_dir:
2852 * Return the path to the lib\locale subfolder of the GLib
2853 * installation folder. The path is in the system codepage. We have to
2854 * use system codepage as bindtextdomain() doesn't have a UTF-8
2857 static const gchar *
2858 _glib_get_locale_dir (void)
2860 gchar *dir, *cp_dir;
2861 gchar *retval = NULL;
2863 dir = g_win32_get_package_installation_directory (GETTEXT_PACKAGE, dll_name);
2864 cp_dir = g_win32_locale_filename_from_utf8 (dir);
2869 /* Don't use g_build_filename() on pathnames in the system
2870 * codepage. In CJK locales cp_dir might end with a double-byte
2871 * character whose trailing byte is a backslash.
2873 retval = g_strconcat (cp_dir, "\\lib\\locale", NULL);
2880 return g_strdup ("");
2883 #undef GLIB_LOCALE_DIR
2884 #define GLIB_LOCALE_DIR _glib_get_locale_dir ()
2886 #endif /* G_OS_WIN32 */
2888 G_CONST_RETURN gchar *
2889 _glib_gettext (const gchar *str)
2891 static gboolean _glib_gettext_initialized = FALSE;
2893 if (!_glib_gettext_initialized)
2895 bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
2896 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
2897 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2899 _glib_gettext_initialized = TRUE;
2902 return dgettext (GETTEXT_PACKAGE, str);
2905 #endif /* ENABLE_NLS */
2909 /* Binary compatibility versions. Not for newly compiled code. */
2911 #undef g_find_program_in_path
2914 g_find_program_in_path (const gchar *program)
2916 gchar *utf8_program = g_locale_to_utf8 (program, -1, NULL, NULL, NULL);
2917 gchar *utf8_retval = g_find_program_in_path_utf8 (utf8_program);
2920 g_free (utf8_program);
2921 if (utf8_retval == NULL)
2923 retval = g_locale_from_utf8 (utf8_retval, -1, NULL, NULL, NULL);
2924 g_free (utf8_retval);
2929 #undef g_get_current_dir
2932 g_get_current_dir (void)
2934 gchar *utf8_dir = g_get_current_dir_utf8 ();
2935 gchar *dir = g_locale_from_utf8 (utf8_dir, -1, NULL, NULL, NULL);
2942 G_CONST_RETURN gchar*
2943 g_getenv (const gchar *variable)
2945 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2946 const gchar *utf8_value = g_getenv_utf8 (utf8_variable);
2950 g_free (utf8_variable);
2953 value = g_locale_from_utf8 (utf8_value, -1, NULL, NULL, NULL);
2954 quark = g_quark_from_string (value);
2957 return g_quark_to_string (quark);
2963 g_setenv (const gchar *variable,
2967 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2968 gchar *utf8_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
2969 gboolean retval = g_setenv_utf8 (utf8_variable, utf8_value, overwrite);
2971 g_free (utf8_variable);
2972 g_free (utf8_value);
2980 g_unsetenv (const gchar *variable)
2982 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2984 g_unsetenv_utf8 (utf8_variable);
2986 g_free (utf8_variable);
2989 #undef g_get_user_name
2991 G_CONST_RETURN gchar*
2992 g_get_user_name (void)
2994 G_LOCK (g_utils_global);
2997 G_UNLOCK (g_utils_global);
2999 return g_user_name_cp;
3002 #undef g_get_real_name
3004 G_CONST_RETURN gchar*
3005 g_get_real_name (void)
3007 G_LOCK (g_utils_global);
3010 G_UNLOCK (g_utils_global);
3012 return g_real_name_cp;
3015 #undef g_get_home_dir
3017 G_CONST_RETURN gchar*
3018 g_get_home_dir (void)
3020 G_LOCK (g_utils_global);
3023 G_UNLOCK (g_utils_global);
3025 return g_home_dir_cp;
3028 #undef g_get_tmp_dir
3030 G_CONST_RETURN gchar*
3031 g_get_tmp_dir (void)
3033 G_LOCK (g_utils_global);
3036 G_UNLOCK (g_utils_global);
3038 return g_tmp_dir_cp;
3043 #define __G_UTILS_C__
3044 #include "galiasdef.c"