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");
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);
1349 for (i = 0; i < len; i++)
1351 eq = strchr (environ[i], '=');
1352 result[i] = g_strndup (environ[i], eq - environ[i]);
1360 G_LOCK_DEFINE_STATIC (g_utils_global);
1362 static gchar *g_tmp_dir = NULL;
1363 static gchar *g_user_name = NULL;
1364 static gchar *g_real_name = NULL;
1365 static gchar *g_home_dir = NULL;
1366 static gchar *g_host_name = NULL;
1369 /* System codepage versions of the above, kept at file level so that they,
1370 * too, are produced only once.
1372 static gchar *g_tmp_dir_cp = NULL;
1373 static gchar *g_user_name_cp = NULL;
1374 static gchar *g_real_name_cp = NULL;
1375 static gchar *g_home_dir_cp = NULL;
1378 static gchar *g_user_data_dir = NULL;
1379 static gchar **g_system_data_dirs = NULL;
1380 static gchar *g_user_cache_dir = NULL;
1381 static gchar *g_user_config_dir = NULL;
1382 static gchar **g_system_config_dirs = NULL;
1387 get_special_folder (int csidl)
1391 wchar_t wc[MAX_PATH+1];
1394 LPITEMIDLIST pidl = NULL;
1396 gchar *retval = NULL;
1398 hr = SHGetSpecialFolderLocation (NULL, csidl, &pidl);
1401 if (G_WIN32_HAVE_WIDECHAR_API ())
1403 b = SHGetPathFromIDListW (pidl, path.wc);
1405 retval = g_utf16_to_utf8 (path.wc, -1, NULL, NULL, NULL);
1409 b = SHGetPathFromIDListA (pidl, path.c);
1411 retval = g_locale_to_utf8 (path.c, -1, NULL, NULL, NULL);
1413 CoTaskMemFree (pidl);
1419 get_windows_directory_root (void)
1421 char windowsdir[MAX_PATH];
1423 if (GetWindowsDirectory (windowsdir, sizeof (windowsdir)))
1425 /* Usually X:\Windows, but in terminal server environments
1426 * might be an UNC path, AFAIK.
1428 char *p = (char *) g_path_skip_root (windowsdir);
1429 if (G_IS_DIR_SEPARATOR (p[-1]) && p[-2] != ':')
1432 return g_strdup (windowsdir);
1435 return g_strdup ("C:\\");
1440 /* HOLDS: g_utils_global_lock */
1442 g_get_any_init (void)
1446 gchar hostname[100];
1448 g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
1450 g_tmp_dir = g_strdup (g_getenv ("TMP"));
1452 g_tmp_dir = g_strdup (g_getenv ("TEMP"));
1456 g_tmp_dir = get_windows_directory_root ();
1462 g_tmp_dir = g_strdup (P_tmpdir);
1463 k = strlen (g_tmp_dir);
1464 if (k > 1 && G_IS_DIR_SEPARATOR (g_tmp_dir[k - 1]))
1465 g_tmp_dir[k - 1] = '\0';
1471 g_tmp_dir = g_strdup ("/tmp");
1473 #endif /* !G_OS_WIN32 */
1476 /* We check $HOME first for Win32, though it is a last resort for Unix
1477 * where we prefer the results of getpwuid().
1479 g_home_dir = g_strdup (g_getenv ("HOME"));
1481 /* Only believe HOME if it is an absolute path and exists */
1484 if (!(g_path_is_absolute (g_home_dir) &&
1485 g_file_test (g_home_dir, G_FILE_TEST_IS_DIR)))
1487 g_free (g_home_dir);
1492 /* In case HOME is Unix-style (it happens), convert it to
1498 while ((p = strchr (g_home_dir, '/')) != NULL)
1504 /* USERPROFILE is probably the closest equivalent to $HOME? */
1505 if (g_getenv ("USERPROFILE") != NULL)
1506 g_home_dir = g_strdup (g_getenv ("USERPROFILE"));
1510 g_home_dir = get_special_folder (CSIDL_PROFILE);
1513 g_home_dir = get_windows_directory_root ();
1514 #endif /* G_OS_WIN32 */
1518 struct passwd *pw = NULL;
1519 gpointer buffer = NULL;
1522 # if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R)
1524 # ifdef _SC_GETPW_R_SIZE_MAX
1525 /* This reurns the maximum length */
1526 glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
1530 # else /* _SC_GETPW_R_SIZE_MAX */
1532 # endif /* _SC_GETPW_R_SIZE_MAX */
1537 /* we allocate 6 extra bytes to work around a bug in
1538 * Mac OS < 10.3. See #156446
1540 buffer = g_malloc (bufsize + 6);
1543 # ifdef HAVE_POSIX_GETPWUID_R
1544 error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
1545 error = error < 0 ? errno : error;
1546 # else /* HAVE_NONPOSIX_GETPWUID_R */
1547 /* HPUX 11 falls into the HAVE_POSIX_GETPWUID_R case */
1548 # if defined(_AIX) || defined(__hpux)
1549 error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1550 pw = error == 0 ? &pwd : NULL;
1552 pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
1553 error = pw ? 0 : errno;
1555 # endif /* HAVE_NONPOSIX_GETPWUID_R */
1559 /* we bail out prematurely if the user id can't be found
1560 * (should be pretty rare case actually), or if the buffer
1561 * should be sufficiently big and lookups are still not
1564 if (error == 0 || error == ENOENT)
1566 g_warning ("getpwuid_r(): failed due to unknown user id (%lu)",
1567 (gulong) getuid ());
1570 if (bufsize > 32 * 1024)
1572 g_warning ("getpwuid_r(): failed due to: %s.",
1573 g_strerror (error));
1581 # endif /* HAVE_POSIX_GETPWUID_R || HAVE_NONPOSIX_GETPWUID_R */
1586 pw = getpwuid (getuid ());
1591 g_user_name = g_strdup (pw->pw_name);
1593 if (pw->pw_gecos && *pw->pw_gecos != '\0')
1595 gchar **gecos_fields;
1598 /* split the gecos field and substitute '&' */
1599 gecos_fields = g_strsplit (pw->pw_gecos, ",", 0);
1600 name_parts = g_strsplit (gecos_fields[0], "&", 0);
1601 pw->pw_name[0] = g_ascii_toupper (pw->pw_name[0]);
1602 g_real_name = g_strjoinv (pw->pw_name, name_parts);
1603 g_strfreev (gecos_fields);
1604 g_strfreev (name_parts);
1608 g_home_dir = g_strdup (pw->pw_dir);
1613 #else /* !HAVE_PWD_H */
1616 if (G_WIN32_HAVE_WIDECHAR_API ())
1618 guint len = UNLEN+1;
1619 wchar_t buffer[UNLEN+1];
1621 if (GetUserNameW (buffer, (LPDWORD) &len))
1623 g_user_name = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL);
1624 g_real_name = g_strdup (g_user_name);
1629 guint len = UNLEN+1;
1630 char buffer[UNLEN+1];
1632 if (GetUserNameA (buffer, (LPDWORD) &len))
1634 g_user_name = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
1635 g_real_name = g_strdup (g_user_name);
1638 #endif /* G_OS_WIN32 */
1640 #endif /* !HAVE_PWD_H */
1644 g_home_dir = g_strdup (g_getenv ("HOME"));
1648 /* change '\\' in %HOME% to '/' */
1649 g_strdelimit (g_home_dir, "\\",'/');
1652 g_user_name = g_strdup ("somebody");
1654 g_real_name = g_strdup ("Unknown");
1657 if (gethostname (hostname, sizeof (hostname)) == -1)
1658 g_host_name = g_strdup ("unknown");
1660 g_host_name = g_strdup (hostname);
1663 DWORD size = sizeof (hostname);
1665 if (!GetComputerName (hostname, &size))
1666 g_host_name = g_strdup ("unknown");
1668 g_host_name = g_strdup (hostname);
1673 g_tmp_dir_cp = g_locale_from_utf8 (g_tmp_dir, -1, NULL, NULL, NULL);
1674 g_user_name_cp = g_locale_from_utf8 (g_user_name, -1, NULL, NULL, NULL);
1675 g_real_name_cp = g_locale_from_utf8 (g_real_name, -1, NULL, NULL, NULL);
1678 g_tmp_dir_cp = g_strdup ("\\");
1679 if (!g_user_name_cp)
1680 g_user_name_cp = g_strdup ("somebody");
1681 if (!g_real_name_cp)
1682 g_real_name_cp = g_strdup ("Unknown");
1684 /* home_dir might be NULL, unlike tmp_dir, user_name and
1688 g_home_dir_cp = g_locale_from_utf8 (g_home_dir, -1, NULL, NULL, NULL);
1690 g_home_dir_cp = NULL;
1691 #endif /* G_OS_WIN32 */
1698 * Gets the user name of the current user. The encoding of the returned
1699 * string is system-defined. On UNIX, it might be the preferred file name
1700 * encoding, or something else, and there is no guarantee that it is even
1701 * consistent on a machine. On Windows, it is always UTF-8.
1703 * Returns: the user name of the current user.
1705 G_CONST_RETURN gchar*
1706 g_get_user_name (void)
1708 G_LOCK (g_utils_global);
1711 G_UNLOCK (g_utils_global);
1719 * Gets the real name of the user. This usually comes from the user's entry
1720 * in the <filename>passwd</filename> file. The encoding of the returned
1721 * string is system-defined. (On Windows, it is, however, always UTF-8.)
1722 * If the real user name cannot be determined, the string "Unknown" is
1725 * Returns: the user's real name.
1727 G_CONST_RETURN gchar*
1728 g_get_real_name (void)
1730 G_LOCK (g_utils_global);
1733 G_UNLOCK (g_utils_global);
1741 * Gets the current user's home directory.
1743 * Note that in contrast to traditional UNIX tools, this function
1744 * prefers <filename>passwd</filename> entries over the <envar>HOME</envar>
1745 * environment variable.
1747 * Returns: the current user's home directory.
1749 G_CONST_RETURN gchar*
1750 g_get_home_dir (void)
1752 G_LOCK (g_utils_global);
1755 G_UNLOCK (g_utils_global);
1763 * Gets the directory to use for temporary files. This is found from
1764 * inspecting the environment variables <envar>TMPDIR</envar>,
1765 * <envar>TMP</envar>, and <envar>TEMP</envar> in that order. If none
1766 * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows.
1767 * The encoding of the returned string is system-defined. On Windows,
1768 * it is always UTF-8. The return value is never %NULL.
1770 * Returns: the directory to use for temporary files.
1772 G_CONST_RETURN gchar*
1773 g_get_tmp_dir (void)
1775 G_LOCK (g_utils_global);
1778 G_UNLOCK (g_utils_global);
1786 * Return a name for the machine.
1788 * The returned name is not necessarily a fully-qualified domain name,
1789 * or even present in DNS or some other name service at all. It need
1790 * not even be unique on your local network or site, but usually it
1791 * is. Callers should not rely on the return value having any specific
1792 * properties like uniqueness for security purposes. Even if the name
1793 * of the machine is changed while an application is running, the
1794 * return value from this function does not change. The returned
1795 * string is owned by GLib and should not be modified or freed. If no
1796 * name can be determined, a default fixed string "unknown" is
1800 g_get_host_name (void)
1802 G_LOCK (g_utils_global);
1805 G_UNLOCK (g_utils_global);
1810 G_LOCK_DEFINE_STATIC (g_prgname);
1811 static gchar *g_prgname = NULL;
1816 * Gets the name of the program. This name should <emphasis>not</emphasis>
1817 * be localized, contrast with g_get_application_name().
1818 * (If you are using GDK or GTK+ the program name is set in gdk_init(),
1819 * which is called by gtk_init(). The program name is found by taking
1820 * the last component of <literal>argv[0]</literal>.)
1822 * Returns: the name of the program. The returned string belongs
1823 * to GLib and must not be modified or freed.
1826 g_get_prgname (void)
1832 if (g_prgname == NULL)
1834 static gboolean beenhere = FALSE;
1838 gchar *utf8_buf = NULL;
1841 if (G_WIN32_HAVE_WIDECHAR_API ())
1843 wchar_t buf[MAX_PATH+1];
1844 if (GetModuleFileNameW (GetModuleHandle (NULL),
1845 buf, G_N_ELEMENTS (buf)) > 0)
1846 utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL);
1850 gchar buf[MAX_PATH+1];
1851 if (GetModuleFileNameA (GetModuleHandle (NULL),
1852 buf, G_N_ELEMENTS (buf)) > 0)
1853 utf8_buf = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
1857 g_prgname = g_path_get_basename (utf8_buf);
1864 G_UNLOCK (g_prgname);
1871 * @prgname: the name of the program.
1873 * Sets the name of the program. This name should <emphasis>not</emphasis>
1874 * be localized, contrast with g_set_application_name(). Note that for
1875 * thread-safety reasons this function can only be called once.
1878 g_set_prgname (const gchar *prgname)
1882 g_prgname = g_strdup (prgname);
1883 G_UNLOCK (g_prgname);
1886 G_LOCK_DEFINE_STATIC (g_application_name);
1887 static gchar *g_application_name = NULL;
1890 * g_get_application_name:
1892 * Gets a human-readable name for the application, as set by
1893 * g_set_application_name(). This name should be localized if
1894 * possible, and is intended for display to the user. Contrast with
1895 * g_get_prgname(), which gets a non-localized name. If
1896 * g_set_application_name() has not been called, returns the result of
1897 * g_get_prgname() (which may be %NULL if g_set_prgname() has also not
1900 * Return value: human-readable application name. may return %NULL
1904 G_CONST_RETURN gchar*
1905 g_get_application_name (void)
1909 G_LOCK (g_application_name);
1910 retval = g_application_name;
1911 G_UNLOCK (g_application_name);
1914 return g_get_prgname ();
1920 * g_set_application_name:
1921 * @application_name: localized name of the application
1923 * Sets a human-readable name for the application. This name should be
1924 * localized if possible, and is intended for display to the user.
1925 * Contrast with g_set_prgname(), which sets a non-localized name.
1926 * g_set_prgname() will be called automatically by gtk_init(),
1927 * but g_set_application_name() will not.
1929 * Note that for thread safety reasons, this function can only
1932 * The application name will be used in contexts such as error messages,
1933 * or when displaying an application's name in the task list.
1937 g_set_application_name (const gchar *application_name)
1939 gboolean already_set = FALSE;
1941 G_LOCK (g_application_name);
1942 if (g_application_name)
1945 g_application_name = g_strdup (application_name);
1946 G_UNLOCK (g_application_name);
1949 g_warning ("g_set_application() name called multiple times");
1953 * g_get_user_data_dir:
1955 * Returns a base directory in which to access application data such
1956 * as icons that is customized for a particular user.
1958 * On UNIX platforms this is determined using the mechanisms described in
1959 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
1960 * XDG Base Directory Specification</ulink>
1962 * Return value: a string owned by GLib that must not be modified
1966 G_CONST_RETURN gchar*
1967 g_get_user_data_dir (void)
1971 G_LOCK (g_utils_global);
1973 if (!g_user_data_dir)
1976 data_dir = get_special_folder (CSIDL_PERSONAL);
1978 data_dir = (gchar *) g_getenv ("XDG_DATA_HOME");
1980 if (data_dir && data_dir[0])
1981 data_dir = g_strdup (data_dir);
1983 if (!data_dir || !data_dir[0])
1989 data_dir = g_build_filename (g_home_dir, ".local",
1992 data_dir = g_build_filename (g_tmp_dir, g_user_name, ".local",
1996 g_user_data_dir = data_dir;
1999 data_dir = g_user_data_dir;
2001 G_UNLOCK (g_utils_global);
2007 * g_get_user_config_dir:
2009 * Returns a base directory in which to store user-specific application
2010 * configuration information such as user preferences and settings.
2012 * On UNIX platforms this is determined using the mechanisms described in
2013 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2014 * XDG Base Directory Specification</ulink>
2016 * Return value: a string owned by GLib that must not be modified
2020 G_CONST_RETURN gchar*
2021 g_get_user_config_dir (void)
2025 G_LOCK (g_utils_global);
2027 if (!g_user_config_dir)
2030 config_dir = get_special_folder (CSIDL_APPDATA);
2032 config_dir = (gchar *) g_getenv ("XDG_CONFIG_HOME");
2034 if (config_dir && config_dir[0])
2035 config_dir = g_strdup (config_dir);
2037 if (!config_dir || !config_dir[0])
2043 config_dir = g_build_filename (g_home_dir, ".config", NULL);
2045 config_dir = g_build_filename (g_tmp_dir, g_user_name, ".config", NULL);
2047 g_user_config_dir = config_dir;
2050 config_dir = g_user_config_dir;
2052 G_UNLOCK (g_utils_global);
2058 * g_get_user_cache_dir:
2060 * Returns a base directory in which to store non-essential, cached
2061 * data specific to particular user.
2063 * On UNIX platforms this is determined using the mechanisms described in
2064 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2065 * XDG Base Directory Specification</ulink>
2067 * Return value: a string owned by GLib that must not be modified
2071 G_CONST_RETURN gchar*
2072 g_get_user_cache_dir (void)
2076 G_LOCK (g_utils_global);
2078 if (!g_user_cache_dir)
2081 cache_dir = get_special_folder (CSIDL_INTERNET_CACHE); /* XXX correct? */
2083 cache_dir = (gchar *) g_getenv ("XDG_CACHE_HOME");
2085 if (cache_dir && cache_dir[0])
2086 cache_dir = g_strdup (cache_dir);
2088 if (!cache_dir || !cache_dir[0])
2094 cache_dir = g_build_filename (g_home_dir, ".cache", NULL);
2096 cache_dir = g_build_filename (g_tmp_dir, g_user_name, ".cache", NULL);
2098 g_user_cache_dir = cache_dir;
2101 cache_dir = g_user_cache_dir;
2103 G_UNLOCK (g_utils_global);
2110 #undef g_get_system_data_dirs
2113 get_module_for_address (gconstpointer address)
2115 /* Holds the g_utils_global lock */
2117 static gboolean beenhere = FALSE;
2118 typedef BOOL (WINAPI *t_GetModuleHandleExA) (DWORD, LPCTSTR, HMODULE *);
2119 static t_GetModuleHandleExA p_GetModuleHandleExA = NULL;
2127 p_GetModuleHandleExA =
2128 (t_GetModuleHandleExA) GetProcAddress (LoadLibrary ("kernel32.dll"),
2129 "GetModuleHandleExA");
2133 if (p_GetModuleHandleExA == NULL ||
2134 !(*p_GetModuleHandleExA) (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
2135 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
2138 MEMORY_BASIC_INFORMATION mbi;
2139 VirtualQuery (address, &mbi, sizeof (mbi));
2140 hmodule = (HMODULE) mbi.AllocationBase;
2147 get_module_share_dir (gconstpointer address)
2150 gchar *filename = NULL;
2153 hmodule = get_module_for_address (address);
2154 if (hmodule == NULL)
2157 if (G_WIN32_IS_NT_BASED ())
2159 wchar_t wfilename[MAX_PATH];
2160 if (GetModuleFileNameW (hmodule, wfilename, G_N_ELEMENTS (wfilename)))
2161 filename = g_utf16_to_utf8 (wfilename, -1, NULL, NULL, NULL);
2165 char cpfilename[MAX_PATH];
2166 if (GetModuleFileNameA (hmodule, cpfilename, G_N_ELEMENTS (cpfilename)))
2167 filename = g_locale_to_utf8 (cpfilename, -1, NULL, NULL, NULL);
2170 if (filename == NULL)
2173 if ((p = strrchr (filename, G_DIR_SEPARATOR)) != NULL)
2176 p = strrchr (filename, G_DIR_SEPARATOR);
2177 if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
2180 retval = g_build_filename (filename, "share", NULL);
2186 G_CONST_RETURN gchar * G_CONST_RETURN *
2187 g_win32_get_system_data_dirs_for_module (gconstpointer address)
2191 static GHashTable *per_module_data_dirs = NULL;
2197 G_LOCK (g_utils_global);
2198 hmodule = get_module_for_address (address);
2199 if (hmodule != NULL)
2201 if (per_module_data_dirs == NULL)
2202 per_module_data_dirs = g_hash_table_new (NULL, NULL);
2205 retval = g_hash_table_lookup (per_module_data_dirs, hmodule);
2209 G_UNLOCK (g_utils_global);
2210 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2216 data_dirs = g_array_new (TRUE, TRUE, sizeof (char *));
2218 /* Documents and Settings\All Users\Application Data */
2219 p = get_special_folder (CSIDL_COMMON_APPDATA);
2221 g_array_append_val (data_dirs, p);
2223 /* Documents and Settings\All Users\Documents */
2224 p = get_special_folder (CSIDL_COMMON_DOCUMENTS);
2226 g_array_append_val (data_dirs, p);
2228 /* Using the above subfolders of Documents and Settings perhaps
2229 * makes sense from a Windows perspective.
2231 * But looking at the actual use cases of this function in GTK+
2232 * and GNOME software, what we really want is the "share"
2233 * subdirectory of the installation directory for the package
2234 * our caller is a part of.
2236 * The address parameter, if non-NULL, points to a function in the
2237 * calling module. Use that to determine that module's installation
2238 * folder, and use its "share" subfolder.
2240 * Additionally, also use the "share" subfolder of the installation
2241 * locations of GLib and the .exe file being run.
2243 * To guard against none of the above being what is really wanted,
2244 * callers of this function should have Win32-specific code to look
2245 * up their installation folder themselves, and handle a subfolder
2246 * "share" of it in the same way as the folders returned from this
2250 p = get_module_share_dir (address);
2252 g_array_append_val (data_dirs, p);
2254 p = g_win32_get_package_installation_subdirectory (NULL, dll_name, "share");
2256 g_array_append_val (data_dirs, p);
2258 p = g_win32_get_package_installation_subdirectory (NULL, NULL, "share");
2260 g_array_append_val (data_dirs, p);
2262 retval = (gchar **) g_array_free (data_dirs, FALSE);
2266 if (hmodule != NULL)
2267 g_hash_table_insert (per_module_data_dirs, hmodule, retval);
2268 G_UNLOCK (g_utils_global);
2271 return (G_CONST_RETURN gchar * G_CONST_RETURN *) retval;
2277 * g_get_system_data_dirs:
2279 * Returns an ordered list of base directories in which to access
2280 * system-wide application data.
2282 * On UNIX platforms this is determined using the mechanisms described in
2283 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2284 * XDG Base Directory Specification</ulink>
2286 * On Windows the first elements in the list are the Application Data
2287 * and Documents folders for All Users. (These can be determined only
2288 * on Windows 2000 or later and are not present in the list on other
2289 * Windows versions.) See documentation for CSIDL_COMMON_APPDATA and
2290 * CSIDL_COMMON_DOCUMENTS.
2292 * Then follows the "share" subfolder in the installation folder for
2293 * the package containing the DLL that calls this function, if it can
2296 * Finally the list contains the "share" subfolder in the installation
2297 * folder for GLib, and in the installation folder for the package the
2298 * application's .exe file belongs to.
2300 * The installation folders above are determined by looking up the
2301 * folder where the module (DLL or EXE) in question is located. If the
2302 * folder's name is "bin", its parent is used, otherwise the folder
2305 * Note that on Windows the returned list can vary depending on where
2306 * this function is called.
2308 * Return value: a %NULL-terminated array of strings owned by GLib that must
2309 * not be modified or freed.
2312 G_CONST_RETURN gchar * G_CONST_RETURN *
2313 g_get_system_data_dirs (void)
2315 gchar **data_dir_vector;
2317 G_LOCK (g_utils_global);
2319 if (!g_system_data_dirs)
2322 data_dir_vector = (gchar **) g_win32_get_system_data_dirs_for_module (NULL);
2324 gchar *data_dirs = (gchar *) g_getenv ("XDG_DATA_DIRS");
2326 if (!data_dirs || !data_dirs[0])
2327 data_dirs = "/usr/local/share/:/usr/share/";
2329 data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2332 g_system_data_dirs = data_dir_vector;
2335 data_dir_vector = g_system_data_dirs;
2337 G_UNLOCK (g_utils_global);
2339 return (G_CONST_RETURN gchar * G_CONST_RETURN *) data_dir_vector;
2343 * g_get_system_config_dirs:
2345 * Returns an ordered list of base directories in which to access
2346 * system-wide configuration information.
2348 * On UNIX platforms this is determined using the mechanisms described in
2349 * the <ulink url="http://www.freedesktop.org/Standards/basedir-spec">
2350 * XDG Base Directory Specification</ulink>
2352 * Return value: a %NULL-terminated array of strings owned by GLib that must
2353 * not be modified or freed.
2356 G_CONST_RETURN gchar * G_CONST_RETURN *
2357 g_get_system_config_dirs (void)
2359 gchar *conf_dirs, **conf_dir_vector;
2361 G_LOCK (g_utils_global);
2363 if (!g_system_config_dirs)
2366 conf_dirs = get_special_folder (CSIDL_COMMON_APPDATA);
2369 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2374 /* Return empty list */
2375 conf_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0);
2378 conf_dirs = (gchar *) g_getenv ("XDG_CONFIG_DIRS");
2380 if (!conf_dirs || !conf_dirs[0])
2381 conf_dirs = "/etc/xdg";
2383 conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
2386 g_system_config_dirs = conf_dir_vector;
2389 conf_dir_vector = g_system_config_dirs;
2390 G_UNLOCK (g_utils_global);
2392 return (G_CONST_RETURN gchar * G_CONST_RETURN *) conf_dir_vector;
2397 static GHashTable *alias_table = NULL;
2399 /* read an alias file for the locales */
2401 read_aliases (gchar *file)
2407 alias_table = g_hash_table_new (g_str_hash, g_str_equal);
2408 fp = fopen (file,"r");
2411 while (fgets (buf, 256, fp))
2417 /* Line is a comment */
2418 if ((buf[0] == '#') || (buf[0] == '\0'))
2421 /* Reads first column */
2422 for (p = buf, q = NULL; *p; p++) {
2423 if ((*p == '\t') || (*p == ' ') || (*p == ':')) {
2426 while ((*q == '\t') || (*q == ' ')) {
2432 /* The line only had one column */
2433 if (!q || *q == '\0')
2436 /* Read second column */
2437 for (p = q; *p; p++) {
2438 if ((*p == '\t') || (*p == ' ')) {
2444 /* Add to alias table if necessary */
2445 if (!g_hash_table_lookup (alias_table, buf)) {
2446 g_hash_table_insert (alias_table, g_strdup (buf), g_strdup (q));
2455 unalias_lang (char *lang)
2462 read_aliases ("/usr/share/locale/locale.alias");
2465 while ((p = g_hash_table_lookup (alias_table, lang)) && (strcmp (p, lang) != 0))
2470 static gboolean said_before = FALSE;
2472 g_warning ("Too many alias levels for a locale, "
2473 "may indicate a loop");
2482 /* Mask for components of locale spec. The ordering here is from
2483 * least significant to most significant
2487 COMPONENT_CODESET = 1 << 0,
2488 COMPONENT_TERRITORY = 1 << 1,
2489 COMPONENT_MODIFIER = 1 << 2
2492 /* Break an X/Open style locale specification into components
2495 explode_locale (const gchar *locale,
2501 const gchar *uscore_pos;
2502 const gchar *at_pos;
2503 const gchar *dot_pos;
2507 uscore_pos = strchr (locale, '_');
2508 dot_pos = strchr (uscore_pos ? uscore_pos : locale, '.');
2509 at_pos = strchr (dot_pos ? dot_pos : (uscore_pos ? uscore_pos : locale), '@');
2513 mask |= COMPONENT_MODIFIER;
2514 *modifier = g_strdup (at_pos);
2517 at_pos = locale + strlen (locale);
2521 mask |= COMPONENT_CODESET;
2522 *codeset = g_strndup (dot_pos, at_pos - dot_pos);
2529 mask |= COMPONENT_TERRITORY;
2530 *territory = g_strndup (uscore_pos, dot_pos - uscore_pos);
2533 uscore_pos = dot_pos;
2535 *language = g_strndup (locale, uscore_pos - locale);
2541 * Compute all interesting variants for a given locale name -
2542 * by stripping off different components of the value.
2544 * For simplicity, we assume that the locale is in
2545 * X/Open format: language[_territory][.codeset][@modifier]
2547 * TODO: Extend this to handle the CEN format (see the GNUlibc docs)
2548 * as well. We could just copy the code from glibc wholesale
2549 * but it is big, ugly, and complicated, so I'm reluctant
2550 * to do so when this should handle 99% of the time...
2553 _g_compute_locale_variants (const gchar *locale)
2555 GSList *retval = NULL;
2565 g_return_val_if_fail (locale != NULL, NULL);
2567 mask = explode_locale (locale, &language, &territory, &codeset, &modifier);
2569 /* Iterate through all possible combinations, from least attractive
2570 * to most attractive.
2572 for (i = 0; i <= mask; i++)
2573 if ((i & ~mask) == 0)
2575 gchar *val = g_strconcat (language,
2576 (i & COMPONENT_TERRITORY) ? territory : "",
2577 (i & COMPONENT_CODESET) ? codeset : "",
2578 (i & COMPONENT_MODIFIER) ? modifier : "",
2580 retval = g_slist_prepend (retval, val);
2584 if (mask & COMPONENT_CODESET)
2586 if (mask & COMPONENT_TERRITORY)
2588 if (mask & COMPONENT_MODIFIER)
2594 /* The following is (partly) taken from the gettext package.
2595 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. */
2597 static const gchar *
2598 guess_category_value (const gchar *category_name)
2600 const gchar *retval;
2602 /* The highest priority value is the `LANGUAGE' environment
2603 variable. This is a GNU extension. */
2604 retval = g_getenv ("LANGUAGE");
2605 if ((retval != NULL) && (retval[0] != '\0'))
2608 /* `LANGUAGE' is not set. So we have to proceed with the POSIX
2609 methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some
2610 systems this can be done by the `setlocale' function itself. */
2612 /* Setting of LC_ALL overwrites all other. */
2613 retval = g_getenv ("LC_ALL");
2614 if ((retval != NULL) && (retval[0] != '\0'))
2617 /* Next comes the name of the desired category. */
2618 retval = g_getenv (category_name);
2619 if ((retval != NULL) && (retval[0] != '\0'))
2622 /* Last possibility is the LANG environment variable. */
2623 retval = g_getenv ("LANG");
2624 if ((retval != NULL) && (retval[0] != '\0'))
2627 #ifdef G_PLATFORM_WIN32
2628 /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and
2629 * LANG, which we already did above. Oh well. The main point of
2630 * calling g_win32_getlocale() is to get the thread's locale as used
2631 * by Windows and the Microsoft C runtime (in the "English_United
2632 * States" format) translated into the Unixish format.
2634 retval = g_win32_getlocale ();
2635 if ((retval != NULL) && (retval[0] != '\0'))
2642 typedef struct _GLanguageNamesCache GLanguageNamesCache;
2644 struct _GLanguageNamesCache {
2646 gchar **language_names;
2650 language_names_cache_free (gpointer data)
2652 GLanguageNamesCache *cache = data;
2653 g_free (cache->languages);
2654 g_strfreev (cache->language_names);
2659 * g_get_language_names:
2661 * Computes a list of applicable locale names, which can be used to
2662 * e.g. construct locale-dependent filenames or search paths. The returned
2663 * list is sorted from most desirable to least desirable and always contains
2664 * the default locale "C".
2666 * For example, if LANGUAGE=de:en_US, then the returned list is
2667 * "de", "en_US", "en", "C".
2669 * This function consults the environment variables <envar>LANGUAGE</envar>,
2670 * <envar>LC_ALL</envar>, <envar>LC_MESSAGES</envar> and <envar>LANG</envar>
2671 * to find the list of locales specified by the user.
2673 * Return value: a %NULL-terminated array of strings owned by GLib
2674 * that must not be modified or freed.
2678 G_CONST_RETURN gchar * G_CONST_RETURN *
2679 g_get_language_names (void)
2681 static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT;
2682 GLanguageNamesCache *cache = g_static_private_get (&cache_private);
2687 cache = g_new0 (GLanguageNamesCache, 1);
2688 g_static_private_set (&cache_private, cache, language_names_cache_free);
2691 value = guess_category_value ("LC_MESSAGES");
2695 if (!(cache->languages && strcmp (cache->languages, value) == 0))
2702 g_free (cache->languages);
2703 g_strfreev (cache->language_names);
2704 cache->languages = g_strdup (value);
2706 alist = g_strsplit (value, ":", 0);
2708 for (a = alist; *a; a++)
2710 gchar *b = unalias_lang (*a);
2711 list = g_slist_concat (list, _g_compute_locale_variants (b));
2714 list = g_slist_append (list, g_strdup ("C"));
2716 cache->language_names = languages = g_new (gchar *, g_slist_length (list) + 1);
2717 for (l = list, i = 0; l; l = l->next, i++)
2718 languages[i] = l->data;
2719 languages[i] = NULL;
2721 g_slist_free (list);
2724 return (G_CONST_RETURN gchar * G_CONST_RETURN *) cache->language_names;
2729 * @v: a #gpointer key
2731 * Converts a gpointer to a hash value.
2732 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2733 * when using pointers as keys in a #GHashTable.
2735 * Returns: a hash value corresponding to the key.
2738 g_direct_hash (gconstpointer v)
2740 return GPOINTER_TO_UINT (v);
2746 * @v2: a key to compare with @v1.
2748 * Compares two #gpointer arguments and returns %TRUE if they are equal.
2749 * It can be passed to g_hash_table_new() as the @key_equal_func
2750 * parameter, when using pointers as keys in a #GHashTable.
2752 * Returns: %TRUE if the two keys match.
2755 g_direct_equal (gconstpointer v1,
2763 * @v1: a pointer to a #gint key.
2764 * @v2: a pointer to a #gint key to compare with @v1.
2766 * Compares the two #gint values being pointed to and returns
2767 * %TRUE if they are equal.
2768 * It can be passed to g_hash_table_new() as the @key_equal_func
2769 * parameter, when using pointers to integers as keys in a #GHashTable.
2771 * Returns: %TRUE if the two keys match.
2774 g_int_equal (gconstpointer v1,
2777 return *((const gint*) v1) == *((const gint*) v2);
2782 * @v: a pointer to a #gint key
2784 * Converts a pointer to a #gint to a hash value.
2785 * It can be passed to g_hash_table_new() as the @hash_func parameter,
2786 * when using pointers to integers values as keys in a #GHashTable.
2788 * Returns: a hash value corresponding to the key.
2791 g_int_hash (gconstpointer v)
2793 return *(const gint*) v;
2797 * g_nullify_pointer:
2798 * @nullify_location: the memory address of the pointer.
2800 * Set the pointer at the specified location to %NULL.
2803 g_nullify_pointer (gpointer *nullify_location)
2805 g_return_if_fail (nullify_location != NULL);
2807 *nullify_location = NULL;
2813 * Get the codeset for the current locale.
2815 * Return value: a newly allocated string containing the name
2816 * of the codeset. This string must be freed with g_free().
2819 g_get_codeset (void)
2821 const gchar *charset;
2823 g_get_charset (&charset);
2825 return g_strdup (charset);
2828 /* This is called from g_thread_init(). It's used to
2829 * initialize some static data in a threadsafe way.
2832 _g_utils_thread_init (void)
2834 g_get_language_names ();
2839 #include <libintl.h>
2844 * _glib_get_locale_dir:
2846 * Return the path to the lib\locale subfolder of the GLib
2847 * installation folder. The path is in the system codepage. We have to
2848 * use system codepage as bindtextdomain() doesn't have a UTF-8
2851 static const gchar *
2852 _glib_get_locale_dir (void)
2854 gchar *dir, *cp_dir;
2855 gchar *retval = NULL;
2857 dir = g_win32_get_package_installation_directory (GETTEXT_PACKAGE, dll_name);
2858 cp_dir = g_win32_locale_filename_from_utf8 (dir);
2863 /* Don't use g_build_filename() on pathnames in the system
2864 * codepage. In CJK locales cp_dir might end with a double-byte
2865 * character whose trailing byte is a backslash.
2867 retval = g_strconcat (cp_dir, "\\lib\\locale", NULL);
2874 return g_strdup ("");
2877 #undef GLIB_LOCALE_DIR
2878 #define GLIB_LOCALE_DIR _glib_get_locale_dir ()
2880 #endif /* G_OS_WIN32 */
2882 G_CONST_RETURN gchar *
2883 _glib_gettext (const gchar *str)
2885 static gboolean _glib_gettext_initialized = FALSE;
2887 if (!_glib_gettext_initialized)
2889 bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
2890 # ifdef HAVE_BIND_TEXTDOMAIN_CODESET
2891 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2893 _glib_gettext_initialized = TRUE;
2896 return dgettext (GETTEXT_PACKAGE, str);
2899 #endif /* ENABLE_NLS */
2903 /* Binary compatibility versions. Not for newly compiled code. */
2905 #undef g_find_program_in_path
2908 g_find_program_in_path (const gchar *program)
2910 gchar *utf8_program = g_locale_to_utf8 (program, -1, NULL, NULL, NULL);
2911 gchar *utf8_retval = g_find_program_in_path_utf8 (utf8_program);
2914 g_free (utf8_program);
2915 if (utf8_retval == NULL)
2917 retval = g_locale_from_utf8 (utf8_retval, -1, NULL, NULL, NULL);
2918 g_free (utf8_retval);
2923 #undef g_get_current_dir
2926 g_get_current_dir (void)
2928 gchar *utf8_dir = g_get_current_dir_utf8 ();
2929 gchar *dir = g_locale_from_utf8 (utf8_dir, -1, NULL, NULL, NULL);
2936 G_CONST_RETURN gchar*
2937 g_getenv (const gchar *variable)
2939 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2940 const gchar *utf8_value = g_getenv_utf8 (utf8_variable);
2944 g_free (utf8_variable);
2947 value = g_locale_from_utf8 (utf8_value, -1, NULL, NULL, NULL);
2948 quark = g_quark_from_string (value);
2951 return g_quark_to_string (quark);
2957 g_setenv (const gchar *variable,
2961 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2962 gchar *utf8_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
2963 gboolean retval = g_setenv_utf8 (utf8_variable, utf8_value, overwrite);
2965 g_free (utf8_variable);
2966 g_free (utf8_value);
2974 g_unsetenv (const gchar *variable)
2976 gchar *utf8_variable = g_locale_to_utf8 (variable, -1, NULL, NULL, NULL);
2978 g_unsetenv_utf8 (utf8_variable);
2980 g_free (utf8_variable);
2983 #undef g_get_user_name
2985 G_CONST_RETURN gchar*
2986 g_get_user_name (void)
2988 G_LOCK (g_utils_global);
2991 G_UNLOCK (g_utils_global);
2993 return g_user_name_cp;
2996 #undef g_get_real_name
2998 G_CONST_RETURN gchar*
2999 g_get_real_name (void)
3001 G_LOCK (g_utils_global);
3004 G_UNLOCK (g_utils_global);
3006 return g_real_name_cp;
3009 #undef g_get_home_dir
3011 G_CONST_RETURN gchar*
3012 g_get_home_dir (void)
3014 G_LOCK (g_utils_global);
3017 G_UNLOCK (g_utils_global);
3019 return g_home_dir_cp;
3022 #undef g_get_tmp_dir
3024 G_CONST_RETURN gchar*
3025 g_get_tmp_dir (void)
3027 G_LOCK (g_utils_global);
3030 G_UNLOCK (g_utils_global);
3032 return g_tmp_dir_cp;
3037 #define __G_UTILS_C__
3038 #include "galiasdef.c"