62
63
#define getegid() 0
65
67
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
66
68
const gchar *env_dir);
71
const guint gimp_major_version = GIMP_MAJOR_VERSION;
72
const guint gimp_minor_version = GIMP_MINOR_VERSION;
73
const guint gimp_micro_version = GIMP_MICRO_VERSION;
78
* @plug_in: must be %TRUE if this function is called from a plug-in
80
* You don't need to care about this function. It is being called for
81
* you automatically (by means of the MAIN() macro that every plug-in
82
* runs). Calling it again will cause a fatal error.
87
gimp_env_init (gboolean plug_in)
89
static gboolean gimp_env_initialized = FALSE;
91
if (gimp_env_initialized)
92
g_error ("gimp_env_init() must only be called once!");
94
gimp_env_initialized = TRUE;
99
_gimp_reloc_init_lib (NULL);
101
else if (_gimp_reloc_init (NULL))
103
/* Set $LD_LIBRARY_PATH to ensure that plugins can be loaded. */
105
const gchar *ldpath = g_getenv ("LD_LIBRARY_PATH");
106
gchar *libdir = _gimp_reloc_find_lib_dir (NULL);
108
if (ldpath && *ldpath)
110
gchar *tmp = g_strconcat (libdir, ":", ldpath, NULL);
112
g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
118
g_setenv ("LD_LIBRARY_PATH", libdir, TRUE);
83
140
* return some non-empty string, whether it corresponds to an existing
84
141
* directory or not.
86
* The returned string is allocated just once, and should *NOT* be
87
* freed with g_free(). The returned string is in the encoding used
88
* for filenames by the system, which isn't necessarily UTF-8 (never
143
* The returned string is owned by GIMP and must not be modified or
144
* freed. The returned string is in the encoding used for filenames by
145
* the system, which isn't necessarily UTF-8 (never is on Windows).
91
147
* Returns: The user-specific GIMP settings directory.
111
167
gimp_dir = g_strdup (env_gimp_dir);
117
gimp_dir = g_build_filename (home_dir,
173
gimp_dir = g_build_filename (home_dir,
123
gimp_dir = g_build_filename (gimp_data_directory (),
179
gimp_dir = g_build_filename (gimp_data_directory (),
124
180
env_gimp_dir, NULL);
132
gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
188
gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
136
gchar *user_name = g_strdup (g_get_user_name ());
192
gchar *user_name = g_strdup (g_get_user_name ());
139
195
#ifdef G_OS_WIN32
140
gchar *p = user_name;
196
gchar *p = user_name;
144
/* Replace funny characters in the user name with an
145
* underscore. The code below also replaces some
146
* characters that in fact are legal in file names, but
147
* who cares, as long as the definitely illegal ones are
150
if (!isalnum (*p) && !strchr ("-.,@=", *p))
200
/* Replace funny characters in the user name with an
201
* underscore. The code below also replaces some
202
* characters that in fact are legal in file names, but
203
* who cares, as long as the definitely illegal ones are
206
if (!g_ascii_isalnum (*p) && !strchr ("-.,@=", *p))
156
212
#ifndef G_OS_WIN32
157
g_message ("warning: no home directory.");
213
g_message ("warning: no home directory.");
159
subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
160
gimp_dir = g_build_filename (gimp_data_directory (),
215
subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
216
gimp_dir = g_build_filename (gimp_data_directory (),
164
g_free (subdir_name);
220
g_free (subdir_name);
187
243
return g_build_filename (gimp_directory (), basename, NULL);
192
247
gimp_toplevel_directory (void)
194
/* Figure it out from the executable name */
195
249
static gchar *toplevel = NULL;
197
gchar filename[MAX_PATH];
203
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
204
g_error ("GetModuleFilename failed");
206
/* If the executable file name is of the format
207
* <foobar>\bin\*.exe or
208
* <foobar>\lib\gimp\GIMP_API_VERSION\plug-ins\*.exe, use <foobar>.
209
* Otherwise, use the directory where the executable is.
212
sep1 = _mbsrchr (filename, '\\');
215
sep2 = _mbsrchr (filename, '\\');
218
if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
224
gchar test[MAX_PATH];
226
g_snprintf (test, sizeof (test) - 1,
227
"\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
229
if (strlen (filename) > strlen (test) &&
230
g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
233
filename[strlen (filename) - strlen (test)] = '\0';
238
toplevel = g_strdup (filename);
256
/* Figure it out from the executable name */
260
if (G_WIN32_HAVE_WIDECHAR_API ())
262
wchar_t w_filename[MAX_PATH];
264
if (GetModuleFileNameW (NULL,
265
w_filename, G_N_ELEMENTS (w_filename)) == 0)
266
g_error ("GetModuleFilenameW failed");
268
filename = g_utf16_to_utf8 (w_filename, -1, NULL, NULL, NULL);
269
if (filename == NULL)
270
g_error ("Converting module filename to UTF-8 failed");
274
gchar cp_filename[MAX_PATH];
276
if (GetModuleFileNameA (NULL,
277
cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
278
g_error ("GetModuleFilenameA failed");
280
filename = g_locale_to_utf8 (cp_filename, -1, NULL, NULL, NULL);
281
if (filename == NULL)
282
g_error ("Converting module filename to UTF-8 failed");
285
/* If the executable file name is of the format
286
* <foobar>\bin\*.exe or
287
* <foobar>\lib\gimp\GIMP_API_VERSION\plug-ins\*.exe, use <foobar>.
288
* Otherwise, use the directory where the executable is.
291
sep1 = strrchr (filename, '\\');
294
sep2 = strrchr (filename, '\\');
297
if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
303
gchar test[MAX_PATH];
305
g_snprintf (test, sizeof (test) - 1,
306
"\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
308
if (strlen (filename) > strlen (test) &&
309
g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
312
filename[strlen (filename) - strlen (test)] = '\0';
320
toplevel = _gimp_reloc_find_prefix (PREFIX);
245
327
* gimp_data_directory:
250
332
* directory is used. On Win32, the installation directory as deduced
251
333
* from the executable's name is used.
253
* The returned string is allocated just once, and should *NOT* be
254
* freed with g_free(). The returned string is in the encoding used
255
* for filenames by the system, which isn't necessarily UTF-8 (never
335
* The returned string is owned by GIMP and must not be modified or
336
* freed. The returned string is in the encoding used for filenames by
337
* the system, which isn't necessarily UTF-8 (never is on Windows).
258
339
* Returns: The top directory for GIMP data.
277
363
* directory is used. On Win32, the installation directory as deduced
278
364
* from the executable's name is used.
280
* The returned string is allocated just once, and should *NOT* be
281
* freed with g_free(). The returned string is in the encoding used
282
* for filenames by the system, which isn't necessarily UTF-8 (never
366
* The returned string is owned by GIMP and must not be modified or
367
* freed. The returned string is in the encoding used for filenames by
368
* the system, which isn't necessarily UTF-8 (never is on Windows).
285
370
* Returns: The top directory for GIMP locale files.
304
394
* directory is used. On Win32, the installation directory as deduced
305
395
* from the executable's name is used.
307
* The returned string is allocated just once, and should *NOT* be
308
* freed with g_free(). The returned string is in the encoding used
309
* for filenames by the system, which isn't necessarily UTF-8 (never
397
* The returned string is owned by GIMP and must not be modified or
398
* freed. The returned string is in the encoding used for filenames by
399
* the system, which isn't necessarily UTF-8 (never is on Windows).
312
401
* Returns: The top directory for GIMP config files.
331
425
* defined directory is used. On Win32, the installation directory as
332
426
* deduced from the executable's name is used.
334
* The returned string is allocated just once, and should *NOT* be
335
* freed with g_free(). The returned string is in the encoding used
336
* for filenames by the system, which isn't necessarily UTF-8 (never
428
* The returned string is owned by GIMP and must not be modified or
429
* freed. The returned string is in the encoding used for filenames by
430
* the system, which isn't necessarily UTF-8 (never is on Windows).
339
432
* Returns: The top directory for GIMP plug_ins and modules.
355
453
* Returns the name of the GIMP's application-specific gtkrc file.
357
* The returned string is allocated just once, and should *NOT* be
358
* freed with g_free(). The returned string is in the encoding used
359
* for filenames by the system, which isn't necessarily UTF-8 (never
455
* The returned string is owned by GIMP and must not be modified or
456
* freed. The returned string is in the encoding used for filenames by
457
* the system, which isn't necessarily UTF-8 (never is on Windows).
362
459
* Returns: The name of the GIMP's application-specific gtkrc file.
421
520
gchar *p = *path;
422
521
if (!g_path_is_absolute (p))
523
*path = g_build_filename (gimp_toplevel_directory (), *path, NULL);
529
if (strncmp (*path, PREFIX G_DIR_SEPARATOR_S,
530
strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
532
/* This is a compile-time entry. Replace the path with the
533
* real one on this machine.
424
536
*path = g_build_filename (gimp_toplevel_directory (),
537
*path + strlen (PREFIX G_DIR_SEPARATOR_S),
465
578
if (! patharray[i])
468
581
#ifndef G_OS_WIN32
469
582
if (*patharray[i] == '~')
471
dir = g_string_new (home);
472
g_string_append (dir, patharray[i] + 1);
584
dir = g_string_new (home);
585
g_string_append (dir, patharray[i] + 1);
477
gimp_path_runtime_fix (&patharray[i]);
478
dir = g_string_new (patharray[i]);
590
gimp_path_runtime_fix (&patharray[i]);
591
dir = g_string_new (patharray[i]);
482
595
exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);
485
list = g_list_prepend (list, g_strdup (dir->str));
598
list = g_list_prepend (list, g_strdup (dir->str));
486
599
else if (check_failed)
487
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
600
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
489
602
g_string_free (dir, TRUE);
512
625
gimp_path_to_str (GList *path)
516
629
gchar *retval = NULL;
518
631
for (list = path; list; list = g_list_next (list))
520
gchar *dir = (gchar *) list->data;
633
gchar *dir = list->data;
524
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
525
g_string_append (str, dir);
637
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
638
g_string_append (str, dir);
529
str = g_string_new (dir);
642
str = g_string_new (dir);
587
700
if (!err && S_ISDIR (filestat.st_mode) &&
589
((filestat.st_mode & S_IWUSR) ||
591
((filestat.st_mode & S_IWGRP) &&
592
(euid != filestat.st_uid)) ||
594
((filestat.st_mode & S_IWOTH) &&
595
(euid != filestat.st_uid) &&
596
(egid != filestat.st_gid))))
598
return g_strdup (dir);
702
((filestat.st_mode & S_IWUSR) ||
704
((filestat.st_mode & S_IWGRP) &&
705
(euid != filestat.st_uid)) ||
707
((filestat.st_mode & S_IWOTH) &&
708
(euid != filestat.st_uid) &&
709
(egid != filestat.st_gid))))
711
return g_strdup (dir);