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>
49 #ifdef HAVE_CRT_EXTERNS_H
50 #include <crt-externs.h> /* for _NSGetEnviron */
53 /* implement gutils's inline functions
55 #define G_IMPLEMENT_INLINES 1
58 #include "gprintfint.h"
59 #include "gthreadinit.h"
63 #define G_PATH_LENGTH MAXPATHLEN
64 #elif defined (PATH_MAX)
65 #define G_PATH_LENGTH PATH_MAX
66 #elif defined (_PC_PATH_MAX)
67 #define G_PATH_LENGTH sysconf(_PC_PATH_MAX)
69 #define G_PATH_LENGTH 2048
72 #ifdef G_PLATFORM_WIN32
73 # define STRICT /* Strict typing, please */
76 # ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
77 # define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
78 # define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
80 # include <lmcons.h> /* For UNLEN */
81 #endif /* G_PLATFORM_WIN32 */
86 /* older SDK (e.g. msvc 5.0) does not have these*/
87 # ifndef CSIDL_INTERNET_CACHE
88 # define CSIDL_INTERNET_CACHE 32
90 # ifndef CSIDL_COMMON_APPDATA
91 # define CSIDL_COMMON_APPDATA 35
93 # ifndef CSIDL_COMMON_DOCUMENTS
94 # define CSIDL_COMMON_DOCUMENTS 46
96 # ifndef CSIDL_PROFILE
97 # define CSIDL_PROFILE 40
103 #include <langinfo.h>
106 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
110 const guint glib_major_version = GLIB_MAJOR_VERSION;
111 const guint glib_minor_version = GLIB_MINOR_VERSION;
112 const guint glib_micro_version = GLIB_MICRO_VERSION;
113 const guint glib_interface_age = GLIB_INTERFACE_AGE;
114 const guint glib_binary_age = GLIB_BINARY_AGE;
116 #ifdef G_PLATFORM_WIN32
118 G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name)
123 * glib_check_version:
124 * @required_major: the required major version.
125 * @required_minor: the required major version.
126 * @required_micro: the required major version.
128 * Checks that the GLib library in use is compatible with the
129 * given version. Generally you would pass in the constants
130 * #GLIB_MAJOR_VERSION, #GLIB_MINOR_VERSION, #GLIB_MICRO_VERSION
131 * as the three arguments to this function; that produces
132 * a check that the library in use is compatible with
133 * the version of GLib the application or module was compiled
136 * Compatibility is defined by two things: first the version
137 * of the running library is newer than the version
138 * @required_major.required_minor.@required_micro. Second
139 * the running library must be binary compatible with the
140 * version @required_major.required_minor.@required_micro
141 * (same major version.)
143 * Return value: %NULL if the GLib library is compatible with the
144 * given version, or a string describing the version mismatch.
145 * The returned string is owned by GLib and must not be modified
151 glib_check_version (guint required_major,
152 guint required_minor,
153 guint required_micro)
155 gint glib_effective_micro = 100 * GLIB_MINOR_VERSION + GLIB_MICRO_VERSION;
156 gint required_effective_micro = 100 * required_minor + required_micro;
158 if (required_major > GLIB_MAJOR_VERSION)
159 return "GLib version too old (major mismatch)";
160 if (required_major < GLIB_MAJOR_VERSION)
161 return "GLib version too new (major mismatch)";
162 if (required_effective_micro < glib_effective_micro - GLIB_BINARY_AGE)
163 return "GLib version too new (micro mismatch)";
164 if (required_effective_micro > glib_effective_micro)
165 return "GLib version too old (micro mismatch)";
169 #if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY)
172 * @dest: the destination address to copy the bytes to.
173 * @src: the source address to copy the bytes from.
174 * @len: the number of bytes to copy.
176 * Copies a block of memory @len bytes long, from @src to @dest.
177 * The source and destination areas may overlap.
179 * In order to use this function, you must include
180 * <filename>string.h</filename> yourself, because this macro will
181 * typically simply resolve to memmove() and GLib does not include
182 * <filename>string.h</filename> for you.
185 g_memmove (gpointer dest,
189 gchar* destptr = dest;
190 const gchar* srcptr = src;
191 if (src + len < dest || dest + len < src)
193 bcopy (src, dest, len);
196 else if (dest <= src)
199 *(destptr++) = *(srcptr++);
206 *(--destptr) = *(--srcptr);
209 #endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */
213 * @func: the function to call on normal program termination.
215 * Specifies a function to be called at normal program termination.
218 g_atexit (GVoidFunc func)
221 const gchar *error = NULL;
223 /* keep this in sync with glib.h */
225 #ifdef G_NATIVE_ATEXIT
226 result = ATEXIT (func);
228 error = g_strerror (errno);
229 #elif defined (HAVE_ATEXIT)
230 # ifdef NeXT /* @#%@! NeXTStep */
231 result = !atexit ((void (*)(void)) func);
233 error = g_strerror (errno);
235 result = atexit ((void (*)(void)) func);
237 error = g_strerror (errno);
239 #elif defined (HAVE_ON_EXIT)
240 result = on_exit ((void (*)(int, void *)) func, NULL);
242 error = g_strerror (errno);
245 error = "no implementation";
246 #endif /* G_NATIVE_ATEXIT */
249 g_error ("Could not register atexit() function: %s", error);
252 /* Based on execvp() from GNU Libc.
253 * Some of this code is cut-and-pasted into gspawn.c
257 my_strchrnul (const gchar *str,
260 gchar *p = (gchar*)str;
261 while (*p && (*p != c))
269 static gchar *inner_find_program_in_path (const gchar *program);
272 g_find_program_in_path (const gchar *program)
274 const gchar *last_dot = strrchr (program, '.');
276 if (last_dot == NULL ||
277 strchr (last_dot, '\\') != NULL ||
278 strchr (last_dot, '/') != NULL)
280 const gint program_length = strlen (program);
281 gchar *pathext = g_build_path (";",
282 ".exe;.cmd;.bat;.com",
283 g_getenv ("PATHEXT"),
286 gchar *decorated_program;
292 gchar *q = my_strchrnul (p, ';');
294 decorated_program = g_malloc (program_length + (q-p) + 1);
295 memcpy (decorated_program, program, program_length);
296 memcpy (decorated_program+program_length, p, q-p);
297 decorated_program [program_length + (q-p)] = '\0';
299 retval = inner_find_program_in_path (decorated_program);
300 g_free (decorated_program);
308 } while (*p++ != '\0');
313 return inner_find_program_in_path (program);
319 * g_find_program_in_path:
320 * @program: a program name in the GLib file name encoding
322 * Locates the first executable named @program in the user's path, in the
323 * same way that execvp() would locate it. Returns an allocated string
324 * with the absolute path name, or %NULL if the program is not found in
325 * the path. If @program is already an absolute path, returns a copy of
326 * @program if @program exists and is executable, and %NULL otherwise.
328 * On Windows, if @program does not have a file type suffix, tries
329 * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in
330 * the <envar>PATHEXT</envar> environment variable.
332 * On Windows, it looks for the file in the same way as CreateProcess()
333 * would. This means first in the directory where the executing
334 * program was loaded from, then in the current directory, then in the
335 * Windows 32-bit system directory, then in the Windows directory, and
336 * finally in the directories in the <envar>PATH</envar> environment
337 * variable. If the program is found, the return value contains the
338 * full name including the type suffix.
340 * Return value: absolute path, or %NULL
344 inner_find_program_in_path (const gchar *program)
347 g_find_program_in_path (const gchar *program)
350 const gchar *path, *p;
351 gchar *name, *freeme;
353 const gchar *path_copy;
354 gchar *filename = NULL, *appdir = NULL;
355 gchar *sysdir = NULL, *windir = NULL;
360 g_return_val_if_fail (program != NULL, NULL);
362 /* If it is an absolute path, or a relative path including subdirectories,
363 * don't look in PATH.
365 if (g_path_is_absolute (program)
366 || strchr (program, G_DIR_SEPARATOR) != NULL
368 || strchr (program, '/') != NULL
372 if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
373 !g_file_test (program, G_FILE_TEST_IS_DIR))
374 return g_strdup (program);
379 path = g_getenv ("PATH");
380 #if defined(G_OS_UNIX) || defined(G_OS_BEOS)
383 /* There is no `PATH' in the environment. The default
384 * search path in GNU libc is the current directory followed by
385 * the path `confstr' returns for `_CS_PATH'.
388 /* In GLib we put . last, for security, and don't use the
389 * unportable confstr(); UNIX98 does not actually specify
390 * what to search if PATH is unset. POSIX may, dunno.
393 path = "/bin:/usr/bin:.";
396 if (G_WIN32_HAVE_WIDECHAR_API ())
399 wchar_t wfilename[MAXPATHLEN], wsysdir[MAXPATHLEN],
402 n = GetModuleFileNameW (NULL, wfilename, MAXPATHLEN);
403 if (n > 0 && n < MAXPATHLEN)
404 filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
406 n = GetSystemDirectoryW (wsysdir, MAXPATHLEN);
407 if (n > 0 && n < MAXPATHLEN)
408 sysdir = g_utf16_to_utf8 (wsysdir, -1, NULL, NULL, NULL);
410 n = GetWindowsDirectoryW (wwindir, MAXPATHLEN);
411 if (n > 0 && n < MAXPATHLEN)
412 windir = g_utf16_to_utf8 (wwindir, -1, NULL, NULL, NULL);
417 gchar cpfilename[MAXPATHLEN], cpsysdir[MAXPATHLEN],
418 cpwindir[MAXPATHLEN];
420 n = GetModuleFileNameA (NULL, cpfilename, MAXPATHLEN);
421 if (n > 0 && n < MAXPATHLEN)
422 filename = g_locale_to_utf8 (cpfilename, -1, NULL, NULL, NULL);
424 n = GetSystemDirectoryA (cpsysdir, MAXPATHLEN);
425 if (n > 0 && n < MAXPATHLEN)
426 sysdir = g_locale_to_utf8 (cpsysdir, -1, NULL, NULL, NULL);
428 n = GetWindowsDirectoryA (cpwindir, MAXPATHLEN);
429 if (n > 0 && n < MAXPATHLEN)
430 windir = g_locale_to_utf8 (cpwindir, -1, NULL, NULL, NULL);
435 appdir = g_path_get_dirname (filename);
439 path = g_strdup (path);
443 const gchar *tem = path;
444 path = g_strconcat (windir, ";", path, NULL);
445 g_free ((gchar *) tem);
451 const gchar *tem = path;
452 path = g_strconcat (sysdir, ";", path, NULL);
453 g_free ((gchar *) tem);
458 const gchar *tem = path;
459 path = g_strconcat (".;", path, NULL);
460 g_free ((gchar *) tem);
465 const gchar *tem = path;
466 path = g_strconcat (appdir, ";", path, NULL);
467 g_free ((gchar *) tem);
474 len = strlen (program) + 1;
475 pathlen = strlen (path);
476 freeme = name = g_malloc (pathlen + len + 1);
478 /* Copy the file name at the top, including '\0' */
479 memcpy (name + pathlen + 1, program, len);
480 name = name + pathlen;
481 /* And add the slash before the filename */
482 *name = G_DIR_SEPARATOR;
490 p = my_strchrnul (path, G_SEARCHPATH_SEPARATOR);
493 /* Two adjacent colons, or a colon at the beginning or the end
494 * of `PATH' means to search the current directory.
498 startp = memcpy (name - (p - path), path, p - path);
500 if (g_file_test (startp, G_FILE_TEST_IS_EXECUTABLE) &&
501 !g_file_test (startp, G_FILE_TEST_IS_DIR))
504 ret = g_strdup (startp);
507 g_free ((gchar *) path_copy);
512 while (*p++ != '\0');
516 g_free ((gchar *) path_copy);
523 * g_parse_debug_string:
524 * @string: a list of debug options separated by ':' or "all"
526 * @keys: pointer to an array of #GDebugKey which associate
527 * strings with bit flags.
528 * @nkeys: the number of #GDebugKey<!-- -->s in the array.
530 * Parses a string containing debugging options separated
531 * by ':' into a %guint containing bit flags. This is used
532 * within GDK and GTK+ to parse the debug options passed on the
533 * command line or through environment variables.
535 * Returns: the combined set of bit flags.
538 g_parse_debug_string (const gchar *string,
539 const GDebugKey *keys,
545 g_return_val_if_fail (string != NULL, 0);
547 if (!g_ascii_strcasecmp (string, "all"))
549 for (i=0; i<nkeys; i++)
550 result |= keys[i].value;
554 const gchar *p = string;
556 gboolean done = FALSE;
567 for (i=0; i<nkeys; i++)
568 if (g_ascii_strncasecmp (keys[i].key, p, q - p) == 0 &&
569 keys[i].key[q - p] == '\0')
570 result |= keys[i].value;
581 * @file_name: the name of the file.
583 * Gets the name of the file without any leading directory components.
584 * It returns a pointer into the given file name string.
586 * Return value: the name of the file without any leading directory components.
588 * Deprecated: Use g_path_get_basename() instead, but notice that
589 * g_path_get_basename() allocates new memory for the returned string, unlike
590 * this function which returns a pointer into the argument.
592 G_CONST_RETURN gchar*
593 g_basename (const gchar *file_name)
595 register gchar *base;
597 g_return_val_if_fail (file_name != NULL, NULL);
599 base = strrchr (file_name, G_DIR_SEPARATOR);
603 gchar *q = strrchr (file_name, '/');
604 if (base == NULL || (q != NULL && q > base))
613 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
614 return (gchar*) file_name + 2;
615 #endif /* G_OS_WIN32 */
617 return (gchar*) file_name;
621 * g_path_get_basename:
622 * @file_name: the name of the file.
624 * Gets the last component of the filename. If @file_name ends with a
625 * directory separator it gets the component before the last slash. If
626 * @file_name consists only of directory separators (and on Windows,
627 * possibly a drive letter), a single separator is returned. If
628 * @file_name is empty, it gets ".".
630 * Return value: a newly allocated string containing the last component of
634 g_path_get_basename (const gchar *file_name)
636 register gssize base;
637 register gssize last_nonslash;
641 g_return_val_if_fail (file_name != NULL, NULL);
643 if (file_name[0] == '\0')
645 return g_strdup (".");
647 last_nonslash = strlen (file_name) - 1;
649 while (last_nonslash >= 0 && G_IS_DIR_SEPARATOR (file_name [last_nonslash]))
652 if (last_nonslash == -1)
653 /* string only containing slashes */
654 return g_strdup (G_DIR_SEPARATOR_S);
657 if (last_nonslash == 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
658 /* string only containing slashes and a drive */
659 return g_strdup (G_DIR_SEPARATOR_S);
660 #endif /* G_OS_WIN32 */
662 base = last_nonslash;
664 while (base >=0 && !G_IS_DIR_SEPARATOR (file_name [base]))
668 if (base == -1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
670 #endif /* G_OS_WIN32 */
672 len = last_nonslash - base;
673 retval = g_malloc (len + 1);
674 memcpy (retval, file_name + base + 1, len);
680 * g_path_is_absolute:
681 * @file_name: a file name.
683 * Returns %TRUE if the given @file_name is an absolute file name,
684 * i.e. it contains a full path from the root directory such as "/usr/local"
685 * on UNIX or "C:\windows" on Windows systems.
687 * Returns: %TRUE if @file_name is an absolute path.
690 g_path_is_absolute (const gchar *file_name)
692 g_return_val_if_fail (file_name != NULL, FALSE);
694 if (G_IS_DIR_SEPARATOR (file_name[0]))
698 /* Recognize drive letter on native Windows */
699 if (g_ascii_isalpha (file_name[0]) &&
700 file_name[1] == ':' && G_IS_DIR_SEPARATOR (file_name[2]))
702 #endif /* G_OS_WIN32 */
709 * @file_name: a file name.
711 * Returns a pointer into @file_name after the root component, i.e. after
712 * the "/" in UNIX or "C:\" under Windows. If @file_name is not an absolute
713 * path it returns %NULL.
715 * Returns: a pointer into @file_name after the root component.
717 G_CONST_RETURN gchar*
718 g_path_skip_root (const gchar *file_name)
720 g_return_val_if_fail (file_name != NULL, NULL);
722 #ifdef G_PLATFORM_WIN32
723 /* Skip \\server\share or //server/share */
724 if (G_IS_DIR_SEPARATOR (file_name[0]) &&
725 G_IS_DIR_SEPARATOR (file_name[1]) &&
727 !G_IS_DIR_SEPARATOR (file_name[2]))
731 p = strchr (file_name + 2, G_DIR_SEPARATOR);
734 gchar *q = strchr (file_name + 2, '/');
735 if (p == NULL || (q != NULL && q < p))
745 while (file_name[0] && !G_IS_DIR_SEPARATOR (file_name[0]))
748 /* Possibly skip a backslash after the share name */
749 if (G_IS_DIR_SEPARATOR (file_name[0]))
752 return (gchar *)file_name;
757 /* Skip initial slashes */
758 if (G_IS_DIR_SEPARATOR (file_name[0]))
760 while (G_IS_DIR_SEPARATOR (file_name[0]))
762 return (gchar *)file_name;
767 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':' && G_IS_DIR_SEPARATOR (file_name[2]))
768 return (gchar *)file_name + 3;
775 * g_path_get_dirname:
776 * @file_name: the name of the file.
778 * Gets the directory components of a file name. If the file name has no
779 * directory components "." is returned. The returned string should be
780 * freed when no longer needed.
782 * Returns: the directory components of the file.
785 g_path_get_dirname (const gchar *file_name)
787 register gchar *base;
790 g_return_val_if_fail (file_name != NULL, NULL);
792 base = strrchr (file_name, G_DIR_SEPARATOR);
795 gchar *q = strrchr (file_name, '/');
796 if (base == NULL || (q != NULL && q > base))
803 if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
805 gchar drive_colon_dot[4];
807 drive_colon_dot[0] = file_name[0];
808 drive_colon_dot[1] = ':';
809 drive_colon_dot[2] = '.';
810 drive_colon_dot[3] = '\0';
812 return g_strdup (drive_colon_dot);
815 return g_strdup (".");
818 while (base > file_name && G_IS_DIR_SEPARATOR (*base))
822 /* base points to the char before the last slash.
824 * In case file_name is the root of a drive (X:\) or a child of the
825 * root of a drive (X:\foo), include the slash.
827 * In case file_name is the root share of an UNC path
828 * (\\server\share), add a slash, returning \\server\share\ .
830 * In case file_name is a direct child of a share in an UNC path
831 * (\\server\share\foo), include the slash after the share name,
832 * returning \\server\share\ .
834 if (base == file_name + 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
836 else if (G_IS_DIR_SEPARATOR (file_name[0]) &&
837 G_IS_DIR_SEPARATOR (file_name[1]) &&
839 !G_IS_DIR_SEPARATOR (file_name[2]) &&
840 base >= file_name + 2)
842 const gchar *p = file_name + 2;
843 while (*p && !G_IS_DIR_SEPARATOR (*p))
847 len = (guint) strlen (file_name) + 1;
848 base = g_new (gchar, len + 1);
849 strcpy (base, file_name);
850 base[len-1] = G_DIR_SEPARATOR;
854 if (G_IS_DIR_SEPARATOR (*p))
857 while (*p && !G_IS_DIR_SEPARATOR (*p))
865 len = (guint) 1 + base - file_name;
867 base = g_new (gchar, len + 1);
868 g_memmove (base, file_name, len);
877 * Gets the current directory.
878 * The returned string should be freed when no longer needed. The encoding
879 * of the returned string is system defined. On Windows, it is always UTF-8.
881 * Returns: the current directory.
884 g_get_current_dir (void)
890 if (G_WIN32_HAVE_WIDECHAR_API ())
892 wchar_t dummy[2], *wdir;
895 len = GetCurrentDirectoryW (2, dummy);
896 wdir = g_new (wchar_t, len);
898 if (GetCurrentDirectoryW (len, wdir) == len - 1)
899 dir = g_utf16_to_utf8 (wdir, -1, NULL, NULL, NULL);
905 gchar dummy[2], *cpdir;
908 len = GetCurrentDirectoryA (2, dummy);
909 cpdir = g_new (gchar, len);
911 if (GetCurrentDirectoryA (len, cpdir) == len - 1)
912 dir = g_locale_to_utf8 (cpdir, -1, NULL, NULL, NULL);
918 dir = g_strdup ("\\");
924 gchar *buffer = NULL;
926 static gulong max_len = 0;
929 max_len = (G_PATH_LENGTH == -1) ? 2048 : G_PATH_LENGTH;
931 /* We don't use getcwd(3) on SUNOS, because, it does a popen("pwd")
932 * and, if that wasn't bad enough, hangs in doing so.
934 #if (defined (sun) && !defined (__SVR4)) || !defined(HAVE_GETCWD)
935 buffer = g_new (gchar, max_len + 1);
937 dir = getwd (buffer);
938 #else /* !sun || !HAVE_GETCWD */
939 while (max_len < G_MAXULONG / 2)
941 buffer = g_new (gchar, max_len + 1);
943 dir = getcwd (buffer, max_len);
945 if (dir || errno != ERANGE)
951 #endif /* !sun || !HAVE_GETCWD */
953 if (!dir || !*buffer)
955 /* hm, should we g_error() out here?
956 * this can happen if e.g. "./" has mode \0000
958 buffer[0] = G_DIR_SEPARATOR;
962 dir = g_strdup (buffer);
971 * @variable: the environment variable to get, in the GLib file name encoding.
973 * Returns the value of an environment variable. The name and value
974 * are in the GLib file name encoding. On UNIX, this means the actual
975 * bytes which might or might not be in some consistent character set
976 * and encoding. On Windows, it is in UTF-8. On Windows, in case the
977 * environment variable's value contains references to other
978 * environment variables, they are expanded.
980 * Return value: the value of the environment variable, or %NULL if
981 * the environment variable is not found. The returned string may be
982 * overwritten by the next call to g_getenv(), g_setenv() or
985 G_CONST_RETURN gchar*
986 g_getenv (const gchar *variable)
990 g_return_val_if_fail (variable != NULL, NULL);
992 return getenv (variable);
994 #else /* G_OS_WIN32 */
999 g_return_val_if_fail (variable != NULL, NULL);
1000 g_return_val_if_fail (g_utf8_validate (variable, -1, NULL), NULL);
1002 /* On Windows NT, it is relatively typical that environment
1003 * variables contain references to other environment variables. If
1004 * so, use ExpandEnvironmentStrings(). (In an ideal world, such
1005 * environment variables would be stored in the Registry as
1006 * REG_EXPAND_SZ type values, and would then get automatically
1007 * expanded before a program sees them. But there is broken software
1008 * that stores environment variables as REG_SZ values even if they
1009 * contain references to other environment variables.)
1012 if (G_WIN32_HAVE_WIDECHAR_API ())
1014 wchar_t dummy[2], *wname, *wvalue;
1017 wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1019 len = GetEnvironmentVariableW (wname, dummy, 2);
1029 wvalue = g_new (wchar_t, len);
1031 if (GetEnvironmentVariableW (wname, wvalue, len) != len - 1)
1038 if (wcschr (wvalue, L'%') != NULL)
1040 wchar_t *tem = wvalue;
1042 len = ExpandEnvironmentStringsW (wvalue, dummy, 2);
1046 wvalue = g_new (wchar_t, len);
1048 if (ExpandEnvironmentStringsW (tem, wvalue, len) != len)
1058 value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
1065 gchar dummy[3], *cpname, *cpvalue;
1068 cpname = g_locale_from_utf8 (variable, -1, NULL, NULL, NULL);
1070 g_return_val_if_fail (cpname != NULL, NULL);
1072 len = GetEnvironmentVariableA (cpname, dummy, 2);
1082 cpvalue = g_new (gchar, len);
1084 if (GetEnvironmentVariableA (cpname, cpvalue, len) != len - 1)
1091 if (strchr (cpvalue, '%') != NULL)
1093 gchar *tem = cpvalue;
1095 len = ExpandEnvironmentStringsA (cpvalue, dummy, 3);
1099 cpvalue = g_new (gchar, len);
1101 if (ExpandEnvironmentStringsA (tem, cpvalue, len) != len)
1111 value = g_locale_to_utf8 (cpvalue, -1, NULL, NULL, NULL);
1117 quark = g_quark_from_string (value);
1120 return g_quark_to_string (quark);
1122 #endif /* G_OS_WIN32 */
1127 * @variable: the environment variable to set, must not contain '='.
1128 * @value: the value for to set the variable to.
1129 * @overwrite: whether to change the variable if it already exists.
1131 * Sets an environment variable. Both the variable's name and value
1132 * should be in the GLib file name encoding. On UNIX, this means that
1133 * they can be any sequence of bytes. On Windows, they should be in
1136 * Note that on some systems, when variables are overwritten, the memory
1137 * used for the previous variables and its value isn't reclaimed.
1139 * Returns: %FALSE if the environment variable couldn't be set.
1144 g_setenv (const gchar *variable,
1155 g_return_val_if_fail (variable != NULL, FALSE);
1156 g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
1159 result = setenv (variable, value, overwrite);
1161 if (!overwrite && getenv (variable) != NULL)
1164 /* This results in a leak when you overwrite existing
1165 * settings. It would be fairly easy to fix this by keeping
1166 * our own parallel array or hash table.
1168 string = g_strconcat (variable, "=", value, NULL);
1169 result = putenv (string);
1173 #else /* G_OS_WIN32 */
1177 g_return_val_if_fail (variable != NULL, FALSE);
1178 g_return_val_if_fail (strchr (variable, '=') == NULL, FALSE);
1179 g_return_val_if_fail (g_utf8_validate (variable, -1, NULL), FALSE);
1180 g_return_val_if_fail (g_utf8_validate (value, -1, NULL), FALSE);
1182 if (!overwrite && g_getenv (variable) != NULL)
1185 /* We want to (if possible) set both the environment variable copy
1186 * kept by the C runtime and the one kept by the system.
1188 * We can't use only the C runtime's putenv or _wputenv() as that
1189 * won't work for arbitrary Unicode strings in a "non-Unicode" app
1190 * (with main() and not wmain()). In a "main()" app the C runtime
1191 * initializes the C runtime's environment table by converting the
1192 * real (wide char) environment variables to system codepage, thus
1193 * breaking those that aren't representable in the system codepage.
1195 * As the C runtime's putenv() will also set the system copy, we do
1196 * the putenv() first, then call SetEnvironmentValueW ourselves.
1199 if (G_WIN32_HAVE_WIDECHAR_API ())
1201 wchar_t *wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1202 wchar_t *wvalue = g_utf8_to_utf16 (value, -1, NULL, NULL, NULL);
1203 gchar *tem = g_strconcat (variable, "=", value, NULL);
1204 wchar_t *wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL);
1207 _wputenv (wassignment);
1208 g_free (wassignment);
1210 retval = (SetEnvironmentVariableW (wname, wvalue) != 0);
1217 /* In the non-Unicode case (Win9x), just putenv() is good
1220 gchar *tem = g_strconcat (variable, "=", value, NULL);
1221 gchar *cpassignment = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
1225 retval = (putenv (cpassignment) == 0);
1227 g_free (cpassignment);
1232 #endif /* G_OS_WIN32 */
1235 #ifdef HAVE__NSGETENVIRON
1236 #define environ (*_NSGetEnviron())
1237 #elif !defined(G_OS_WIN32)
1239 /* According to the Single Unix Specification, environ is not in
1240 * any system header, although unistd.h often declares it.
1242 extern char **environ;
1247 * @variable: the environment variable to remove, must not contain '='.
1249 * Removes an environment variable from the environment.
1251 * Note that on some systems, when variables are overwritten, the memory
1252 * used for the previous variables and its value isn't reclaimed.
1253 * Furthermore, this function can't be guaranteed to operate in a
1259 g_unsetenv (const gchar *variable)
1263 #ifdef HAVE_UNSETENV
1264 g_return_if_fail (variable != NULL);
1265 g_return_if_fail (strchr (variable, '=') == NULL);
1267 unsetenv (variable);
1268 #else /* !HAVE_UNSETENV */
1272 g_return_if_fail (variable != NULL);
1273 g_return_if_fail (strchr (variable, '=') == NULL);
1275 len = strlen (variable);
1277 /* Mess directly with the environ array.
1278 * This seems to be the only portable way to do this.
1280 * Note that we remove *all* environment entries for
1281 * the variable name, not just the first.
1286 if (strncmp (*e, variable, len) != 0 || (*e)[len] != '=')
1294 #endif /* !HAVE_UNSETENV */
1296 #else /* G_OS_WIN32 */
1298 g_return_if_fail (variable != NULL);
1299 g_return_if_fail (strchr (variable, '=') == NULL);
1300 g_return_if_fail (g_utf8_validate (variable, -1, NULL));
1302 if (G_WIN32_HAVE_WIDECHAR_API ())
1304 wchar_t *wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);
1305 gchar *tem = g_strconcat (variable, "=", NULL);
1306 wchar_t *wassignment = g_utf8_to_utf16 (tem, -1, NULL, NULL, NULL);
1309 _wputenv (wassignment);
1310 g_free (wassignment);
1312 SetEnvironmentVariableW (wname, NULL);
1318 /* In the non-Unicode case (Win9x), just putenv() is good
1321 gchar *tem = g_strconcat (variable, "=", NULL);
1322 gchar *cpassignment = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
1326 putenv (cpassignment);
1328 g_free (cpassignment);
1331 #endif /* G_OS_WIN32 */
1337 * Gets the names of all variables set in the environment.
1339 * Returns: a %NULL-terminated list of strings which must be freed
1340 * with g_strfreev().
1347 gchar **result, *eq;
1350 len = g_strv_length (environ);
1351 result = g_new0 (gchar *, len + 1);
1354 for (i = 0; i < len; i++)
1356 eq = strchr (environ[i], '=');
1358 result[j++] = g_strndup (environ[i], eq - environ[i]);
1366 G_LOCK_DEFINE_STATIC (g_utils_global);
1368 static gchar *g_tmp_dir = NULL;
1369 static gchar *g_user_name = NULL;
1370 static gchar *g_real_name = NULL;
1371 static gchar *g_home_dir = NULL;
1372 static gchar *g_host_name = NULL;
1375 /* System codepage versions of the above, kept at file level so that they,
1376 * too, are produced only once.
1378 static gchar *g_tmp_dir_cp = NULL;
1379 static gchar *g_user_name_cp = NULL;
1380 static gchar *g_real_name_cp = NULL;
1381 static gchar *g_home_dir_cp = NULL;
1384 static gchar *g_user_data_dir = NULL;
1385 static gchar **g_system_data_dirs = NULL;
1386 static gchar *g_user_cache_dir = NULL;
1387 static gchar *g_user_config_dir = NULL;
1388 static gchar **g_system_config_dirs = NULL;
1393 get_special_folder (int csidl)
1397 wchar_t wc[MAX_PATH+1];
1400 LPITEMIDLIST pidl = NULL;
1402 gchar *retval = NULL;
1404 hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl);
1407 if (G_WIN32_HAVE_WIDECHAR_API ())
1409 b = SHGetPathFromIDListW (pidl, path.wc);
1411 retval = g_utf16_to_utf8 (path.wc, -1, NULL, NULL, NULL);
1415 b = SHGetPathFromIDListA (pidl, path.c);
1417 retval = g_locale_to_utf8 (path.c, -1, NULL, NULL, NULL);
1419 CoTaskMemFree (pidl);
1425 get_windows_directory_root (void)
1427 char windowsdir[MAX_PATH];
1429 if (GetWindowsDirectory (windowsdir, sizeof (windowsdir)))
1431 /* Usually X:\Windows, but in terminal server environments
1432 * might be an UNC path, AFAIK.
1434 char *p = (char *) g_path_skip_root (windowsdir);
1435 if (G_IS_DIR_SEPARATOR (p[-1]) && p[-2] != ':')
1438 return g_strdup (windowsdir);
1441 return g_strdup ("C:\\");
1446 /* HOLDS: g_utils_global_lock */
1448 g_get_any_init_do (void)
1450 gchar hostname[100];
1452 g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
1454 g_tmp_dir = g_strdup (g_getenv ("TMP"));
1456 g_tmp_dir = g_strdup (g_getenv ("TEMP"));
1460 g_tmp_dir = get_windows_directory_root ();
1466 g_tmp_dir = g_strdup (P_tmpdir);
1467 k = strlen (g_tmp_dir);
1468 if (k > 1 && G_IS_DIR_SEPARATOR (g_tmp_dir[k - 1]))
1469 g_tmp_dir[k - 1] = '\0';
1475 g_tmp_dir = g_strdup ("/tmp");
1477 #endif /* !G_OS_WIN32 */
1480 /* We check $HOME first for Win32, though it is a last resort for Unix
1481 * where we prefer the results of getpwuid().
1483 g_home_dir = g_strdup (g_getenv ("HOME"));
1485 /* Only believe HOME if it is an absolute path and exists */
1488 if (!(g_path_is_absolute (g_home_dir) &&
1489 g_file_test (g_home_dir, G_FILE_TEST_IS_DIR)))
1491 g_free (g_home_dir);
1496 /* In case HOME is Unix-style (it happens), convert it to
1502 while ((p = strchr (g_home_dir, '/')) != NULL)
1508 /* USERPROFILE is probably the closest equivalent to $HOME? */
1509 if (g_getenv ("USERPROFILE") != NULL)
1510 g_home_dir = g_strdup (g_getenv ("USERPROFILE"));
1514 g_home_dir = get_special_folder (CSIDL_PROFILE);
1517 g_home_dir = get_windows_directory_root ();
1518 #endif /* G_OS_WIN32 */
1522 struct passwd *pw = NULL;
1523 gpointer buffer = NULL;
1526 # if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R)
1528 # ifdef _SC_GETPW_R_SIZE_MAX
1529 /* This reurns the maximum length */
1530 glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
1534 # else /* _SC_GETPW_R_SIZE_MAX */
1536 # endif /* _SC_GETPW_R_SIZE_MAX */
1541 /* we allocate 6 extra bytes to work around a bug in
1542 * Mac OS < 10.3. See #156446
1544 buffer = g_malloc (bufsize + 6);
1547 # ifdef HAVE_POSIX_GETPWUID_R
1548 error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
1549 error = error < 0 ? errno : error;
1550 # else /* HAVE_NONPOSIX_GETPWUID_R */
1551 /* HPUX 11 falls into the HAVE_POSIX_GETPWUID_R case */
1552 # if defined(_AIX) || defined(__hpux)
1553 error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1554 pw = error == 0 ? &pwd : NULL;
1556 pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1557 error = pw ? 0 : errno;
1559 # endif /* HAVE_NONPOSIX_GETPWUID_R */
1563 /* we bail out prematurely if the user id can't be found
1564 * (should be pretty rare case actually), or if the buffer
1565 * should be sufficiently big and lookups are still not
1568 if (error == 0 || error == ENOENT)
1570 g_warning ("getpwuid_r(): failed due to unknown user id (%lu)",
1571 (gulong) getuid ());
1574 if (bufsize > 32 * 1024)
1576 g_warning ("getpwuid_r(): failed due to: %s.",
1577 g_strerror (error));
1585 # endif /* HAVE_POSIX_GETPWUID_R || HAVE_NONPOSIX_GETPWUID_R */
1590 pw = getpwuid (getuid ());
1595 g_user_name = g_strdup (pw->pw_name);
1597 if (pw->pw_gecos && *pw->pw_gecos != '\0')
1599 gchar **gecos_fields;
1602 /* split the gecos field and substitute '&' */
1603 gecos_fields = g_strsplit (pw->pw_gecos, ",", 0);
1604 name_parts = g_strsplit (gecos_fields[0], "&", 0);
1605 pw->pw_name[0] = g_ascii_toupper (pw->pw_name[0]);
1606 g_real_name = g_strjoinv (pw->pw_name, name_parts);
1607 g_strfreev (gecos_fields);
1608 g_strfreev (name_parts);
1612 g_home_dir = g_strdup (pw->pw_dir);
1617 #else /* !HAVE_PWD_H */
1620 if (G_WIN32_HAVE_WIDECHAR_API ())
1622 guint len = UNLEN+1;
1623 wchar_t buffer[UNLEN+1];
1625 if (GetUserNameW (buffer, (LPDWORD) &len))
1627 g_user_name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
1628 g_real_name = g_strdup (g_user_name);
1633 guint len = UNLEN+1;
1634 char buffer[UNLEN+1];
1636 if (GetUserNameA (buffer, (LPDWORD) &len))
1638 g_user_name = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
1639 g_real_name = g_strdup (g_user_name);
1642 #endif /* G_OS_WIN32 */
1644 #endif /* !HAVE_PWD_H */
1648 g_home_dir = g_strdup (g_getenv ("HOME"));
1652 /* change '\\' in %HOME% to '/' */
1653 g_strdelimit (g_home_dir, "\\",'/');
1656 g_user_name = g_strdup ("somebody");
1658 g_real_name = g_strdup ("Unknown");
1662 gboolean hostname_fail = (gethostname (hostname, sizeof (hostname)) == -1);
1664 DWORD size = sizeof (hostname);
1665 gboolean hostname_fail = (!GetComputerName (hostname, &size));
1667 g_host_name = g_strdup (hostname_fail ? "localhost" : hostname);
1671 g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
1672 g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
1673 g_real_name_cp = g_locale_from_utf8 (g_real_name, -1, NULL, NULL, NULL);
1676 g_tmp_dir_cp = g_strdup ("\\");
1677 if (!g_user_name_cp)
1678 g_user_name_cp = g_strdup ("somebody");
1679 if (!g_real_name_cp)
1680 g_real_name_cp = g_strdup ("Unknown");
1682 /* home_dir might be NULL, unlike tmp_dir, user_name and
1686 g_home_dir_cp = g_locale_from_utf8 (g_home_dir, -1, NULL, NULL, NULL);
1688 g_home_dir_cp = NULL;
1689 #endif /* G_OS_WIN32 */
1693 g_get_any_init (void)
1696 g_get_any_init_do ();
1700 g_get_any_init_locked (void)
1702 G_LOCK (g_utils_global);
1704 G_UNLOCK (g_utils_global);
1711 * Gets the user name of the current user. The encoding of the returned
1712 * string is system-defined. On UNIX, it might be the preferred file name
1713 * encoding, or something else, and there is no guarantee that it is even
1714 * consistent on a machine. On Windows, it is always UTF-8.
1716 * Returns: the user name of the current user.
1718 G_CONST_RETURN gchar*
1719 g_get_user_name (void)
1721 g_get_any_init_locked ();
1728 * Gets the real name of the user. This usually comes from the user's entry
1729 * in the <filename>passwd</filename> file. The encoding of the returned
1730 * string is system-defined. (On Windows, it is, however, always UTF-8.)
1731 * If the real user name cannot be determined, the string "Unknown" is
1734 * Returns: the user's real name.
1736 G_CONST_RETURN gchar*
1737 g_get_real_name (void)
1739 g_get_any_init_locked ();
1746 * Gets the current user's home directory.
1748 * Note that in contrast to traditional UNIX tools, this function
1749 * prefers <filename>passwd</filename> entries over the <envar>HOME</envar>
1750 * environment variable.
1752 * Returns: the current user's home directory.
1754 G_CONST_RETURN gchar*
1755 g_get_home_dir (void)
1757 g_get_any_init_locked ();
1764 * Gets the directory to use for temporary files. This is found from
1765 * inspecting the environment variables <envar>TMPDIR</envar>,
1766 * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none
1767 * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
1768 * The encoding of the returned string is system-defined. On Windows,
1769 * it is always UTF-8. The return value is never %NULL.
1771 * Returns: the directory to use for temporary files.
1773 G_CONST_RETURN gchar*
1774 g_get_tmp_dir (void)
1776 g_get_any_init_locked ();
1783 * Return a name for the machine.
1785 * The returned name is not necessarily a fully-qualified domain name,
1786 * or even present in DNS or some other name service at all. It need
1787 * not even be unique on your local network or site, but usually it
1788 * is. Callers should not rely on the return value having any specific
1789 * properties like uniqueness for security purposes. Even if the name
1790 * of the machine is changed while an application is running, the
1791 * return value from this function does not change. The returned
1792 * string is owned by GLib and should not be modified or freed. If no
1793 * name can be determined, a default fixed string "localhost" is
1796 * Returns: the host name of the machine.
1801 g_get_host_name (void)
1803 g_get_any_init_locked ();
1807 G_LOCK_DEFINE_STATIC (g_prgname);
1808 static gchar *g_prgname = NULL;
1813 * Gets the name of the program. This name should <emphasis>not</emphasis>
1814 * be localized, contrast with g_get_application_name().
1815 * (If you are using GDK or GTK+ the program name is set in gdk_init(),
1816 * which is called by gtk_init(). The program name is found by taking
1817 * the last component of <literal>argv[0]</literal>.)
1819 * Returns: the name of the program. The returned string belongs
1820 * to GLib and must not be modified or freed.
1823 g_get_prgname (void)
1829 if (g_prgname == NULL)
1831 static gboolean beenhere = FALSE;
1835 gchar *utf8_buf = NULL;
1838 if (G_WIN32_HAVE_WIDECHAR_API ())
1840 wchar_t buf[MAX_PATH+1];
1841 if (GetModuleFileNameW (GetModuleHandle (NULL),
1842 buf, G_N_ELEMENTS (buf)) > 0)
1843 utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL);
1847 gchar buf[MAX_PATH+1];
1848 if (GetModuleFileNameA (GetModuleHandle (NULL),
1849 buf, G_N_ELEMENTS (buf)) > 0)
1850 utf8_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
1854 g_prgname = g_path_get_basename (utf8_buf);
1861 G_UNLOCK (g_prgname);
1868 * @prgname: the name of the program.
1870 * Sets the name of the program. This name should <emphasis>not</emphasis>
1871 * be localized, contrast with g_set_application_name(). Note that for
1872 * thread-safety reasons this function can only be called once.
1875 g_set_prgname (const gchar *prgname)
1879 g_prgname = g_strdup (prgname);
1880 G_UNLOCK (g_prgname);
1883 G_LOCK_DEFINE_STATIC (g_application_name);
1884 static gchar *g_application_name = NULL;
1887 * g_get_application_name:
1889 * Gets a human-readable name for the application, as set by
1890 * g_set_application_name(). This name should be localized if
1891 * possible, and is intended for display to the user. Contrast with
1892 * g_get_prgname(), which gets a non-localized name. If
1893 * g_set_application_name() has not been called, returns the result of
1894 * g_get_prgname() (which may be %NULL if g_set_prgname() has also not
1897 * Return value: human-readable application name. may return %NULL
1901 G_CONST_RETURN gchar*
1902 g_get_application_name (void)
1906 G_LOCK (g_application_name);
1907 retval = g_application_name;
1908 G_UNLOCK (g_application_name);
1911 return g_get_prgname ();
1917 * g_set_application_name:
1918 * @application_name: localized name of the application
1920 * Sets a human-readable name for the application. This name should be
1921 * localized if possible, and is intended for display to the user.
1922 * Contrast with g_set_prgname(), which sets a non-localized name.
1923 * g_set_prgname() will be called automatically by gtk_init(),
1924 * but g_set_application_name() will not.
1926 * Note that for thread safety reasons, this function can only
1929 * The application name will be used in contexts such as error messages,
1930 * or when displaying an application's name in the task list.
1934 g_set_application_name (const gchar *application_name)
1936 gboolean already_set = FALSE;
1938 G_LOCK (g_application_name);
1939 if (g_application_name)
1942 g_application_name = g_strdup (application_name);
1943 G_UNLOCK (g_application_name);
1946 g_warning ("g_set_application() name called multiple times");
1950 * g_get_user_data_dir:
1952 * Returns a base directory in which to access application data such
1953 * as icons that is customized for a particular user.
1955 * On UNIX platforms this is determined using the mechanisms described in
1956 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
1957 * XDG Base Directory Specification</ulink>
1959 * Return value: a string owned by GLib that must not be modified
1963 G_CONST_RETURN gchar*
1964 g_get_user_data_dir (void)
1968 G_LOCK (g_utils_global);
1970 if (!g_user_data_dir)
1973 data_dir = get_special_folder (CSIDL_PERSONAL);
1975 data_dir = (gchar *) g_getenv ("XDG_DATA_HOME");
1977 if (data_dir && data_dir[0])
1978 data_dir = g_strdup (data_dir);
1980 if (!data_dir || !data_dir[0])
1985 data_dir = g_build_filename (g_home_dir, ".local",
1988 data_dir = g_build_filename (g_tmp_dir, g_user_name, ".local",
1992 g_user_data_dir = data_dir;
1995 data_dir = g_user_data_dir;
1997 G_UNLOCK (g_utils_global);
2003 * g_get_user_config_dir:
2005 * Returns a base directory in which to store user-specific application
2006 * configuration information such as user preferences and settings.
2008 * On UNIX platforms this is determined using the mechanisms described in
2009 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2010 * XDG Base Directory Specification</ulink>
2012 * Return value: a string owned by GLib that must not be modified
2016 G_CONST_RETURN gchar*
2017 g_get_user_config_dir (void)
2021 G_LOCK (g_utils_global);
2023 if (!g_user_config_dir)
2026 config_dir = get_special_folder (CSIDL_APPDATA);
2028 config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME");
2030 if (config_dir && config_dir[0])
2031 config_dir = g_strdup (config_dir);
2033 if (!config_dir || !config_dir[0])
2038 config_dir = g_build_filename (g_home_dir, ".config", NULL);
2040 config_dir = g_build_filename (g_tmp_dir, g_user_name, ".config", NULL);
2042 g_user_config_dir = config_dir;
2045 config_dir = g_user_config_dir;
2047 G_UNLOCK (g_utils_global);
2053 * g_get_user_cache_dir:
2055 * Returns a base directory in which to store non-essential, cached
2056 * data specific to particular user.
2058 * On UNIX platforms this is determined using the mechanisms described in
2059 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2060 * XDG Base Directory Specification</ulink>
2062 * Return value: a string owned by GLib that must not be modified
2066 G_CONST_RETURN gchar*
2067 g_get_user_cache_dir (void)
2071 G_LOCK (g_utils_global);
2073 if (!g_user_cache_dir)
2076 cache_dir = get_special_folder (CSIDL_INTERNET_CACHE); /* XXX correct? */
2078 cache_dir = (gchar *) g_getenv ("XDG_CACHE_HOME");
2080 if (cache_dir && cache_dir[0])
2081 cache_dir = g_strdup (cache_dir);
2083 if (!cache_dir || !cache_dir[0])
2088 cache_dir = g_build_filename (g_home_dir, ".cache", NULL);
2090 cache_dir = g_build_filename (g_tmp_dir, g_user_name, ".cache", NULL);
2092 g_user_cache_dir = cache_dir;
2095 cache_dir = g_user_cache_dir;
2097 G_UNLOCK (g_utils_global);
2104 #undef g_get_system_data_dirs
2107 get_module_for_address (gconstpointer address)
2109 /* Holds the g_utils_global lock */
2111 static gboolean beenhere = FALSE;
2112 typedef BOOL (WINAPI *t_GetModuleHandleExA) (DWORD, LPCTSTR, HMODULE *);
2113 static t_GetModuleHandleExA p_GetModuleHandleExA = NULL;
2121 p_GetModuleHandleExA =
2122 (t_GetModuleHandleExA) GetProcAddress (LoadLibrary ("kernel32.dll"),
2123 "GetModuleHandleExA");
2127 if (p_GetModuleHandleExA == NULL ||
2128 !(*p_GetModuleHandleExA) (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
2129 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
2132 MEMORY_BASIC_INFORMATION mbi;
2133 VirtualQuery (address, &mbi, sizeof (mbi));
2134 hmodule = (HMODULE) mbi.AllocationBase;
2141 get_module_share_dir (gconstpointer address)
2144 gchar *filename = NULL;
2147 hmodule = get_module_for_address (address);
2148 if (hmodule == NULL)
2151 if (G_WIN32_IS_NT_BASED ())
2153 wchar_t wfilename[MAX_PATH];
2154 if (GetModuleFileNameW (hmodule, wfilename, G_N_ELEMENTS (wfilename)))
2155 filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
2159 char cpfilename[MAX_PATH];
2160 if (GetModuleFileNameA (hmodule, cpfilename, G_N_ELEMENTS (cpfilename)))
2161 filename = g_locale_to_utf8 (cpfilename, -1, NULL, NULL, NULL);
2164 if (filename == NULL)
2167 if ((p = strrchr (filename, G_DIR_SEPARATOR)) != NULL)
2170 p = strrchr (filename, G_DIR_SEPARATOR);
2171 if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
2174 retval = g_build_filename (filename, "share", NULL);
2180 G_CONST_RETURN gchar * G_CONST_RETURN *
2181 g_win32_get_system_data_dirs_for_module (gconstpointer address)
2185 static GHashTable *per_module_data_dirs = NULL;
2191 G_LOCK (g_utils_global);
2192 hmodule = get_module_for_address (address);
2193 if (hmodule != NULL)
2195 if (per_module_data_dirs == NULL)
2196 per_module_data_dirs = g_hash_table_new (NULL, NULL);
2199 retval = g_hash_table_lookup (per_module_data_dirs, hmodule);
2203 G_UNLOCK (g_utils_global);
2204 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2210 data_dirs = g_array_new (TRUE, TRUE, sizeof (char *));
2212 /* Documents and Settings\All Users\Application Data */
2213 p = get_special_folder (CSIDL_COMMON_APPDATA);
2215 g_array_append_val (data_dirs, p);
2217 /* Documents and Settings\All Users\Documents */
2218 p = get_special_folder (CSIDL_COMMON_DOCUMENTS);
2220 g_array_append_val (data_dirs, p);
2222 /* Using the above subfolders of Documents and Settings perhaps
2223 * makes sense from a Windows perspective.
2225 * But looking at the actual use cases of this function in GTK+
2226 * and GNOME software, what we really want is the "share"
2227 * subdirectory of the installation directory for the package
2228 * our caller is a part of.
2230 * The address parameter, if non-NULL, points to a function in the
2231 * calling module. Use that to determine that module's installation
2232 * folder, and use its "share" subfolder.
2234 * Additionally, also use the "share" subfolder of the installation
2235 * locations of GLib and the .exe file being run.
2237 * To guard against none of the above being what is really wanted,
2238 * callers of this function should have Win32-specific code to look
2239 * up their installation folder themselves, and handle a subfolder
2240 * "share" of it in the same way as the folders returned from this
2244 p = get_module_share_dir (address);
2246 g_array_append_val (data_dirs, p);
2248 p = g_win32_get_package_installation_subdirectory (NULL, dll_name, "share");
2250 g_array_append_val (data_dirs, p);
2252 p = g_win32_get_package_installation_subdirectory (NULL, NULL, "share");
2254 g_array_append_val (data_dirs, p);
2256 retval = (gchar **) g_array_free (data_dirs, FALSE);
2260 if (hmodule != NULL)
2261 g_hash_table_insert (per_module_data_dirs, hmodule, retval);
2262 G_UNLOCK (g_utils_global);
2265 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2271 * g_get_system_data_dirs:
2273 * Returns an ordered list of base directories in which to access
2274 * system-wide application data.
2276 * On UNIX platforms this is determined using the mechanisms described in
2277 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2278 * XDG Base Directory Specification</ulink>
2280 * On Windows the first elements in the list are the Application Data
2281 * and Documents folders for All Users. (These can be determined only
2282 * on Windows 2000 or later and are not present in the list on other
2283 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
2284 * CSIDL_COMMON_DOCUMENTS.
2286 * Then follows the "share" subfolder in the installation folder for
2287 * the package containing the DLL that calls this function, if it can
2290 * Finally the list contains the "share" subfolder in the installation
2291 * folder for GLib, and in the installation folder for the package the
2292 * application's .exe file belongs to.
2294 * The installation folders above are determined by looking up the
2295 * folder where the module (DLL or EXE) in question is located. If the
2296 * folder's name is "bin", its parent is used, otherwise the folder
2299 * Note that on Windows the returned list can vary depending on where
2300 * this function is called.
2302 * Return value: a %NULL-terminated array of strings owned by GLib that must
2303 * not be modified or freed.
2306 G_CONST_RETURN gchar * G_CONST_RETURN *
2307 g_get_system_data_dirs (void)
2309 gchar **data_dir_vector;
2311 G_LOCK (g_utils_global);
2313 if (!g_system_data_dirs)
2316 data_dir_vector = (gchar **) g_win32_get_system_data_dirs_for_module (NULL);
2318 gchar *data_dirs = (gchar *) g_getenv ("XDG_DATA_DIRS");
2320 if (!data_dirs || !data_dirs[0])
2321 data_dirs = "/usr/local/share/:/usr/share/";
2323 data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2326 g_system_data_dirs = data_dir_vector;
2329 data_dir_vector = g_system_data_dirs;
2331 G_UNLOCK (g_utils_global);
2333 return (G_CONST_RETURN gchar * G_CONST_RETURN *) data_dir_vector;
2337 * g_get_system_config_dirs:
2339 * Returns an ordered list of base directories in which to access
2340 * system-wide configuration information.
2342 * On UNIX platforms this is determined using the mechanisms described in
2343 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2344 * XDG Base Directory Specification</ulink>
2346 * Return value: a %NULL-terminated array of strings owned by GLib that must
2347 * not be modified or freed.
2350 G_CONST_RETURN gchar * G_CONST_RETURN *
2351 g_get_system_config_dirs (void)
2353 gchar *conf_dirs, **conf_dir_vector;
2355 G_LOCK (g_utils_global);
2357 if (!g_system_config_dirs)
2360 conf_dirs = get_special_folder (CSIDL_COMMON_APPDATA);
2363 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2368 /* Return empty list */
2369 conf_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0);
2372 conf_dirs = (gchar *) g_getenv ("XDG_CONFIG_DIRS");
2374 if (!conf_dirs || !conf_dirs[0])
2375 conf_dirs = "/etc/xdg";
2377 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2380 g_system_config_dirs = conf_dir_vector;
2383 conf_dir_vector = g_system_config_dirs;
2384 G_UNLOCK (g_utils_global);
2386 return (G_CONST_RETURN gchar * G_CONST_RETURN *) conf_dir_vector;
2391 static GHashTable *alias_table = NULL;
2393 /* read an alias file for the locales */
2395 read_aliases (gchar *file)
2401 alias_table = g_hash_table_new (g_str_hash, g_str_equal);
2402 fp = fopen (file,"r");
2405 while (fgets (buf, 256, fp))
2411 /* Line is a comment */
2412 if ((buf[0] == '#') || (buf[0] == '\0'))
2415 /* Reads first column */
2416 for (p = buf, q = NULL; *p; p++) {
2417 if ((*p == '\t') || (*p == ' ') || (*p == ':')) {
2420 while ((*q == '\t') || (*q == ' ')) {
2426 /* The line only had one column */
2427 if (!q || *q == '\0')
2430 /* Read second column */
2431 for (p = q; *p; p++) {
2432 if ((*p == '\t') || (*p == ' ')) {
2438 /* Add to alias table if necessary */
2439 if (!g_hash_table_lookup (alias_table, buf)) {
2440 g_hash_table_insert (alias_table, g_strdup (buf), g_strdup (q));
2449 unalias_lang (char *lang)
2456 read_aliases ("/usr/share/locale/locale.alias");
2459 while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0))
2464 static gboolean said_before = FALSE;
2466 g_warning ("Too many alias levels for a locale, "
2467 "may indicate a loop");
2476 /* Mask for components of locale spec. The ordering here is from
2477 * least significant to most significant
2481 COMPONENT_CODESET = 1 << 0,
2482 COMPONENT_TERRITORY = 1 << 1,
2483 COMPONENT_MODIFIER = 1 << 2
2486 /* Break an X/Open style locale specification into components
2489 explode_locale (const gchar *locale,
2495 const gchar *uscore_pos;
2496 const gchar *at_pos;
2497 const gchar *dot_pos;
2501 uscore_pos = strchr (locale, '_');
2502 dot_pos = strchr (uscore_pos ? uscore_pos : locale, '.');
2503 at_pos = strchr (dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@');
2507 mask |= COMPONENT_MODIFIER;
2508 *modifier = g_strdup (at_pos);
2511 at_pos = locale + strlen (locale);
2515 mask |= COMPONENT_CODESET;
2516 *codeset = g_strndup (dot_pos, at_pos - dot_pos);
2523 mask |= COMPONENT_TERRITORY;
2524 *territory = g_strndup (uscore_pos, dot_pos - uscore_pos);
2527 uscore_pos = dot_pos;
2529 *language = g_strndup (locale, uscore_pos - locale);
2535 * Compute all interesting variants for a given locale name -
2536 * by stripping off different components of the value.
2538 * For simplicity, we assume that the locale is in
2539 * X/Open format: language[_territory][.codeset][@modifier]
2541 * TODO: Extend this to handle the CEN format (see the GNUlibc docs)
2542 * as well. We could just copy the code from glibc wholesale
2543 * but it is big, ugly, and complicated, so I'm reluctant
2544 * to do so when this should handle 99% of the time...
2547 _g_compute_locale_variants (const gchar *locale)
2549 GSList *retval = NULL;
2551 gchar *language = NULL;
2552 gchar *territory = NULL;
2553 gchar *codeset = NULL;
2554 gchar *modifier = NULL;
2559 g_return_val_if_fail (locale != NULL, NULL);
2561 mask = explode_locale (locale, &language, &territory, &codeset, &modifier);
2563 /* Iterate through all possible combinations, from least attractive
2564 * to most attractive.
2566 for (i = 0; i <= mask; i++)
2567 if ((i & ~mask) == 0)
2569 gchar *val = g_strconcat (language,
2570 (i & COMPONENT_TERRITORY) ? territory : "",
2571 (i & COMPONENT_CODESET) ? codeset : "",
2572 (i & COMPONENT_MODIFIER) ? modifier : "",
2574 retval = g_slist_prepend (retval, val);
2578 if (mask & COMPONENT_CODESET)
2580 if (mask & COMPONENT_TERRITORY)
2582 if (mask & COMPONENT_MODIFIER)
2588 /* The following is (partly) taken from the gettext package.
2589 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */
2591 static const gchar *
2592 guess_category_value (const gchar *category_name)
2594 const gchar *retval;
2596 /* The highest priority value is the `LANGUAGE' environment
2597 variable. This is a GNU extension. */
2598 retval = g_getenv ("LANGUAGE");
2599 if ((retval != NULL) && (retval[0] != '\0'))
2602 /* `LANGUAGE' is not set. So we have to proceed with the POSIX
2603 methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some
2604 systems this can be done by the `setlocale' function itself. */
2606 /* Setting of LC_ALL overwrites all other. */
2607 retval = g_getenv ("LC_ALL");
2608 if ((retval != NULL) && (retval[0] != '\0'))
2611 /* Next comes the name of the desired category. */
2612 retval = g_getenv (category_name);
2613 if ((retval != NULL) && (retval[0] != '\0'))
2616 /* Last possibility is the LANG environment variable. */
2617 retval = g_getenv ("LANG");
2618 if ((retval != NULL) && (retval[0] != '\0'))
2621 #ifdef G_PLATFORM_WIN32
2622 /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and
2623 * LANG, which we already did above. Oh well. The main point of
2624 * calling g_win32_getlocale() is to get the thread's locale as used
2625 * by Windows and the Microsoft C runtime (in the "English_United
2626 * States" format) translated into the Unixish format.
2628 retval = g_win32_getlocale ();
2629 if ((retval != NULL) && (retval[0] != '\0'))
2636 typedef struct _GLanguageNamesCache GLanguageNamesCache;
2638 struct _GLanguageNamesCache {
2640 gchar **language_names;
2644 language_names_cache_free (gpointer data)
2646 GLanguageNamesCache *cache = data;
2647 g_free (cache->languages);
2648 g_strfreev (cache->language_names);
2653 * g_get_language_names:
2655 * Computes a list of applicable locale names, which can be used to
2656 * e.g. construct locale-dependent filenames or search paths. The returned
2657 * list is sorted from most desirable to least desirable and always contains
2658 * the default locale "C".
2660 * For example, if LANGUAGE=de:en_US, then the returned list is
2661 * "de", "en_US", "en", "C".
2663 * This function consults the environment variables <envar>LANGUAGE</envar>,
2664 * <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar>
2665 * to find the list of locales specified by the user.
2667 * Return value: a %NULL-terminated array of strings owned by GLib
2668 * that must not be modified or freed.
2672 G_CONST_RETURN gchar * G_CONST_RETURN *
2673 g_get_language_names (void)
2675 static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT;
2676 GLanguageNamesCache *cache = g_static_private_get (&cache_private);
2681 cache = g_new0 (GLanguageNamesCache, 1);
2682 g_static_private_set (&cache_private, cache, language_names_cache_free);
2685 value = guess_category_value ("LC_MESSAGES");
2689 if (!(cache->languages && strcmp (cache->languages, value) == 0))
2696 g_free (cache->languages);
2697 g_strfreev (cache->language_names);
2698 cache->languages = g_strdup (value);
2700 alist = g_strsplit (value, ":", 0);
2702 for (a = alist; *a; a++)
2704 gchar *b = unalias_lang (*a);
2705 list = g_slist_concat (list, _g_compute_locale_variants (b));
2708 list = g_slist_append (list, g_strdup ("C"));
2710 cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1);
2711 for (l = list, i = 0; l; l = l->next, i++)
2712 languages[i] = l->data;
2713 languages[i] = NULL;
2715 g_slist_free (list);
2718 return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names;
2723 * @v: a #gpointer key
2725 * Converts a gpointer to a hash value.
2726 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2727 * when using pointers as keys in a #GHashTable.
2729 * Returns: a hash value corresponding to the key.
2732 g_direct_hash (gconstpointer v)
2734 return GPOINTER_TO_UINT (v);
2740 * @v2: a key to compare with @v1.
2742 * Compares two #gpointer arguments and returns %TRUE if they are equal.
2743 * It can be passed to g_hash_table_new() as the @key_equal_func
2744 * parameter, when using pointers as keys in a #GHashTable.
2746 * Returns: %TRUE if the two keys match.
2749 g_direct_equal (gconstpointer v1,
2757 * @v1: a pointer to a #gint key.
2758 * @v2: a pointer to a #gint key to compare with @v1.
2760 * Compares the two #gint values being pointed to and returns
2761 * %TRUE if they are equal.
2762 * It can be passed to g_hash_table_new() as the @key_equal_func
2763 * parameter, when using pointers to integers as keys in a #GHashTable.
2765 * Returns: %TRUE if the two keys match.
2768 g_int_equal (gconstpointer v1,
2771 return *((const gint*) v1) == *((const gint*) v2);
2776 * @v: a pointer to a #gint key
2778 * Converts a pointer to a #gint to a hash value.
2779 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2780 * when using pointers to integers values as keys in a #GHashTable.
2782 * Returns: a hash value corresponding to the key.
2785 g_int_hash (gconstpointer v)
2787 return *(const gint*) v;
2791 * g_nullify_pointer:
2792 * @nullify_location: the memory address of the pointer.
2794 * Set the pointer at the specified location to %NULL.
2797 g_nullify_pointer (gpointer *nullify_location)
2799 g_return_if_fail (nullify_location != NULL);
2801 *nullify_location = NULL;
2807 * Get the codeset for the current locale.
2809 * Return value: a newly allocated string containing the name
2810 * of the codeset. This string must be freed with g_free().
2813 g_get_codeset (void)
2815 const gchar *charset;
2817 g_get_charset (&charset);
2819 return g_strdup (charset);
2822 /* This is called from g_thread_init(). It's used to
2823 * initialize some static data in a threadsafe way.
2826 _g_utils_thread_init (void)
2828 g_get_language_names ();
2833 #include <libintl.h>
2838 * _glib_get_locale_dir:
2840 * Return the path to the lib\locale subfolder of the GLib
2841 * installation folder. The path is in the system codepage. We have to
2842 * use system codepage as bindtextdomain() doesn't have a UTF-8
2845 static const gchar *
2846 _glib_get_locale_dir (void)
2848 gchar *dir, *cp_dir;
2849 gchar *retval = NULL;
2851 dir = g_win32_get_package_installation_directory (GETTEXT_PACKAGE, dll_name);
2852 cp_dir = g_win32_locale_filename_from_utf8 (dir);
2857 /* Don't use g_build_filename() on pathnames in the system
2858 * codepage. In CJK locales cp_dir might end with a double-byte
2859 * character whose trailing byte is a backslash.
2861 retval = g_strconcat (cp_dir, "\\lib\\locale", NULL);
2868 return g_strdup ("");
2871 #undef GLIB_LOCALE_DIR
2872 #define GLIB_LOCALE_DIR _glib_get_locale_dir ()
2874 #endif /* G_OS_WIN32 */
2876 G_CONST_RETURN gchar *
2877 _glib_gettext (const gchar *str)
2879 static gboolean _glib_gettext_initialized = FALSE;
2881 if (!_glib_gettext_initialized)
2883 bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
2884 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
2885 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2887 _glib_gettext_initialized = TRUE;
2890 return dgettext (GETTEXT_PACKAGE, str);
2893 #endif /* ENABLE_NLS */
2897 /* Binary compatibility versions. Not for newly compiled code. */
2899 #undef g_find_program_in_path
2902 g_find_program_in_path (const gchar *program)
2904 gchar *utf8_program = g_locale_to_utf8 (program, -1, NULL, NULL, NULL);
2905 gchar *utf8_retval = g_find_program_in_path_utf8 (utf8_program);
2908 g_free (utf8_program);
2909 if (utf8_retval == NULL)
2911 retval = g_locale_from_utf8 (utf8_retval, -1, NULL, NULL, NULL);
2912 g_free (utf8_retval);
2917 #undef g_get_current_dir
2920 g_get_current_dir (void)
2922 gchar *utf8_dir = g_get_current_dir_utf8 ();
2923 gchar *dir = g_locale_from_utf8 (utf8_dir, -1, NULL, NULL, NULL);
2930 G_CONST_RETURN gchar*
2931 g_getenv (const gchar *variable)
2933 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2934 const gchar *utf8_value = g_getenv_utf8 (utf8_variable);
2938 g_free (utf8_variable);
2941 value = g_locale_from_utf8 (utf8_value, -1, NULL, NULL, NULL);
2942 quark = g_quark_from_string (value);
2945 return g_quark_to_string (quark);
2951 g_setenv (const gchar *variable,
2955 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2956 gchar *utf8_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
2957 gboolean retval = g_setenv_utf8 (utf8_variable, utf8_value, overwrite);
2959 g_free (utf8_variable);
2960 g_free (utf8_value);
2968 g_unsetenv (const gchar *variable)
2970 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2972 g_unsetenv_utf8 (utf8_variable);
2974 g_free (utf8_variable);
2977 #undef g_get_user_name
2979 G_CONST_RETURN gchar*
2980 g_get_user_name (void)
2982 g_get_any_init_locked ();
2983 return g_user_name_cp;
2986 #undef g_get_real_name
2988 G_CONST_RETURN gchar*
2989 g_get_real_name (void)
2991 g_get_any_init_locked ();
2992 return g_real_name_cp;
2995 #undef g_get_home_dir
2997 G_CONST_RETURN gchar*
2998 g_get_home_dir (void)
3000 g_get_any_init_locked ();
3001 return g_home_dir_cp;
3004 #undef g_get_tmp_dir
3006 G_CONST_RETURN gchar*
3007 g_get_tmp_dir (void)
3009 g_get_any_init_locked ();
3010 return g_tmp_dir_cp;
3015 #define __G_UTILS_C__
3016 #include "galiasdef.c"