~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpbase/gimpenv.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "config.h"
24
24
 
25
 
#include <stdio.h>
26
 
 
27
 
#include <glib.h>
28
 
 
29
 
#include <ctype.h>
30
25
#include <string.h>
31
26
#include <sys/types.h>
32
 
#include <sys/stat.h>
33
27
 
34
28
#ifdef HAVE_UNISTD_H
35
29
#include <unistd.h>
36
30
#endif
37
31
 
 
32
#include <glib.h>
 
33
#include <glib/gstdio.h>
 
34
 
 
35
#ifndef LIBGIMP_COMPILATION
 
36
#define LIBGIMP_COMPILATION
 
37
#endif
 
38
 
38
39
#include "gimpenv.h"
39
40
#include "gimpversion.h"
 
41
#include "gimpreloc.h"
40
42
 
41
43
 
42
44
#ifdef G_OS_WIN32
43
45
#define STRICT
44
 
#define WIN32_LEAN_AND_MEAN     /* without it DATADIR in objidl.h will collide */
45
 
#include <windows.h>            /* For GetModuleFileName */
 
46
#define WIN32_LEAN_AND_MEAN     /* without it DATADIR in objidl.h will collide */
 
47
#include <windows.h>            /* For GetModuleFileName */
46
48
#include <io.h>
47
 
#include <mbstring.h>
48
49
#ifndef S_IWUSR
49
50
# define S_IWUSR _S_IWRITE
50
51
#endif
53
54
#define S_IWOTH (_S_IWRITE>>6)
54
55
#endif
55
56
#ifndef S_ISDIR
56
 
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
57
 
# define S_ISDIR(mode)  __S_ISTYPE((mode), _S_IFDIR)
 
57
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
 
58
# define S_ISDIR(mode)  __S_ISTYPE((mode), _S_IFDIR)
58
59
#endif
59
60
#define uid_t gint
60
61
#define gid_t gint
62
63
#define getegid() 0
63
64
#endif
64
65
 
 
66
 
65
67
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
66
68
                                 const gchar *env_dir);
67
69
 
68
70
 
 
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;
 
74
 
 
75
 
 
76
/**
 
77
 * gimp_env_init:
 
78
 * @plug_in: must be %TRUE if this function is called from a plug-in
 
79
 *
 
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.
 
83
 *
 
84
 * Since: GIMP 2.4
 
85
 */
 
86
void
 
87
gimp_env_init (gboolean plug_in)
 
88
{
 
89
  static gboolean gimp_env_initialized = FALSE;
 
90
 
 
91
  if (gimp_env_initialized)
 
92
    g_error ("gimp_env_init() must only be called once!");
 
93
 
 
94
  gimp_env_initialized = TRUE;
 
95
 
 
96
#ifndef G_OS_WIN32
 
97
  if (plug_in)
 
98
    {
 
99
      _gimp_reloc_init_lib (NULL);
 
100
    }
 
101
  else if (_gimp_reloc_init (NULL))
 
102
    {
 
103
      /* Set $LD_LIBRARY_PATH to ensure that plugins can be loaded. */
 
104
 
 
105
      const gchar *ldpath = g_getenv ("LD_LIBRARY_PATH");
 
106
      gchar       *libdir = _gimp_reloc_find_lib_dir (NULL);
 
107
 
 
108
      if (ldpath && *ldpath)
 
109
        {
 
110
          gchar *tmp = g_strconcat (libdir, ":", ldpath, NULL);
 
111
 
 
112
          g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
 
113
 
 
114
          g_free (tmp);
 
115
        }
 
116
      else
 
117
        {
 
118
          g_setenv ("LD_LIBRARY_PATH", libdir, TRUE);
 
119
        }
 
120
 
 
121
      g_free (libdir);
 
122
    }
 
123
#endif
 
124
}
 
125
 
69
126
/**
70
127
 * gimp_directory:
71
128
 *
83
140
 * return some non-empty string, whether it corresponds to an existing
84
141
 * directory or not.
85
142
 *
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
89
 
 * is on Windows).
 
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).
90
146
 *
91
147
 * Returns: The user-specific GIMP settings directory.
92
148
 **/
111
167
          gimp_dir = g_strdup (env_gimp_dir);
112
168
        }
113
169
      else
114
 
        {
115
 
          if (home_dir)
116
 
            {
117
 
              gimp_dir = g_build_filename (home_dir,
 
170
        {
 
171
          if (home_dir)
 
172
            {
 
173
              gimp_dir = g_build_filename (home_dir,
118
174
                                           env_gimp_dir,
119
175
                                           NULL);
120
 
            }
121
 
          else
122
 
            {
123
 
              gimp_dir = g_build_filename (gimp_data_directory (),
 
176
            }
 
177
          else
 
178
            {
 
179
              gimp_dir = g_build_filename (gimp_data_directory (),
124
180
                                           env_gimp_dir, NULL);
125
 
            }
126
 
        }
 
181
            }
 
182
        }
127
183
    }
128
184
  else
129
185
    {
130
186
      if (home_dir)
131
 
        {
132
 
          gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
133
 
        }
 
187
        {
 
188
          gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
 
189
        }
134
190
      else
135
 
        {
136
 
          gchar *user_name = g_strdup (g_get_user_name ());
137
 
          gchar *subdir_name;
 
191
        {
 
192
          gchar *user_name = g_strdup (g_get_user_name ());
 
193
          gchar *subdir_name;
138
194
 
139
195
#ifdef G_OS_WIN32
140
 
          gchar *p = user_name;
 
196
          gchar *p = user_name;
141
197
 
142
 
          while (*p)
143
 
            {
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
148
 
               * caught.
149
 
               */
150
 
              if (!isalnum (*p) && !strchr ("-.,@=", *p))
151
 
                *p = '_';
152
 
              p++;
153
 
            }
 
198
          while (*p)
 
199
            {
 
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
 
204
               * caught.
 
205
               */
 
206
              if (!g_ascii_isalnum (*p) && !strchr ("-.,@=", *p))
 
207
                *p = '_';
 
208
              p++;
 
209
            }
154
210
#endif
155
211
 
156
212
#ifndef G_OS_WIN32
157
 
          g_message ("warning: no home directory.");
 
213
          g_message ("warning: no home directory.");
158
214
#endif
159
 
          subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
160
 
          gimp_dir = g_build_filename (gimp_data_directory (),
161
 
                                       subdir_name,
 
215
          subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
 
216
          gimp_dir = g_build_filename (gimp_data_directory (),
 
217
                                       subdir_name,
162
218
                                       NULL);
163
 
          g_free (user_name);
164
 
          g_free (subdir_name);
165
 
        }
 
219
          g_free (user_name);
 
220
          g_free (subdir_name);
 
221
        }
166
222
    }
167
223
 
168
224
  return gimp_dir;
187
243
  return g_build_filename (gimp_directory (), basename, NULL);
188
244
}
189
245
 
190
 
#ifdef G_OS_WIN32
191
 
gchar *
 
246
static const gchar *
192
247
gimp_toplevel_directory (void)
193
248
{
194
 
  /* Figure it out from the executable name */
195
249
  static gchar *toplevel = NULL;
196
250
 
197
 
  gchar         filename[MAX_PATH];
198
 
  gchar        *sep1, *sep2;
199
 
 
200
251
  if (toplevel)
201
252
    return toplevel;
202
253
 
203
 
  if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
204
 
    g_error ("GetModuleFilename failed");
205
 
 
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.
210
 
   */
211
 
 
212
 
  sep1 = _mbsrchr (filename, '\\');
213
 
  *sep1 = '\0';
214
 
 
215
 
  sep2 = _mbsrchr (filename, '\\');
216
 
  if (sep2 != NULL)
217
 
    {
218
 
      if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
219
 
        {
220
 
          *sep2 = '\0';
221
 
        }
222
 
      else
223
 
        {
224
 
          gchar test[MAX_PATH];
225
 
 
226
 
          g_snprintf (test, sizeof (test) - 1,
227
 
                      "\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
228
 
 
229
 
          if (strlen (filename) > strlen (test) &&
230
 
              g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
231
 
                                  test) == 0)
232
 
            {
233
 
              filename[strlen (filename) - strlen (test)] = '\0';
234
 
            }
235
 
        }
236
 
    }
237
 
 
238
 
  toplevel = g_strdup (filename);
 
254
#ifdef G_OS_WIN32
 
255
  {
 
256
    /* Figure it out from the executable name */
 
257
    gchar *filename;
 
258
    gchar *sep1, *sep2;
 
259
 
 
260
    if (G_WIN32_HAVE_WIDECHAR_API ())
 
261
      {
 
262
        wchar_t w_filename[MAX_PATH];
 
263
 
 
264
        if (GetModuleFileNameW (NULL,
 
265
                                w_filename, G_N_ELEMENTS (w_filename)) == 0)
 
266
          g_error ("GetModuleFilenameW failed");
 
267
 
 
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");
 
271
      }
 
272
    else
 
273
      {
 
274
        gchar cp_filename[MAX_PATH];
 
275
 
 
276
        if (GetModuleFileNameA (NULL,
 
277
                                cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
 
278
          g_error ("GetModuleFilenameA failed");
 
279
 
 
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");
 
283
      }
 
284
 
 
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.
 
289
     */
 
290
 
 
291
    sep1 = strrchr (filename, '\\');
 
292
    *sep1 = '\0';
 
293
 
 
294
    sep2 = strrchr (filename, '\\');
 
295
    if (sep2 != NULL)
 
296
      {
 
297
        if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
 
298
          {
 
299
            *sep2 = '\0';
 
300
          }
 
301
        else
 
302
          {
 
303
            gchar test[MAX_PATH];
 
304
 
 
305
            g_snprintf (test, sizeof (test) - 1,
 
306
                        "\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
 
307
 
 
308
            if (strlen (filename) > strlen (test) &&
 
309
                g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
 
310
                                    test) == 0)
 
311
              {
 
312
                filename[strlen (filename) - strlen (test)] = '\0';
 
313
              }
 
314
          }
 
315
      }
 
316
 
 
317
    toplevel = filename;
 
318
  }
 
319
#else
 
320
  toplevel = _gimp_reloc_find_prefix (PREFIX);
 
321
#endif
239
322
 
240
323
  return toplevel;
241
324
}
242
 
#endif
243
325
 
244
326
/**
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.
252
334
 *
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
256
 
 * is on Windows).
 
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).
257
338
 *
258
339
 * Returns: The top directory for GIMP data.
259
340
 **/
263
344
  static gchar *gimp_data_dir = NULL;
264
345
 
265
346
  if (! gimp_data_dir)
266
 
    gimp_data_dir = gimp_env_get_dir ("GIMP2_DATADIR", DATADIR);
 
347
    {
 
348
      gchar *tmp = _gimp_reloc_find_data_dir (DATADIR);
 
349
 
 
350
      gimp_data_dir = gimp_env_get_dir ("GIMP2_DATADIR", tmp);
 
351
      g_free (tmp);
 
352
    }
267
353
 
268
354
  return gimp_data_dir;
269
355
}
277
363
 * directory is used.  On Win32, the installation directory as deduced
278
364
 * from the executable's name is used.
279
365
 *
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
283
 
 * is on Windows).
 
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).
284
369
 *
285
370
 * Returns: The top directory for GIMP locale files.
286
371
 */
290
375
  static gchar *gimp_locale_dir = NULL;
291
376
 
292
377
  if (! gimp_locale_dir)
293
 
    gimp_locale_dir = gimp_env_get_dir ("GIMP2_LOCALEDIR", LOCALEDIR);
 
378
    {
 
379
      gchar *tmp = _gimp_reloc_find_locale_dir (LOCALEDIR);
 
380
 
 
381
      gimp_locale_dir = gimp_env_get_dir ("GIMP2_LOCALEDIR", tmp);
 
382
      g_free (tmp);
 
383
    }
294
384
 
295
385
  return gimp_locale_dir;
296
386
}
304
394
 * directory is used.  On Win32, the installation directory as deduced
305
395
 * from the executable's name is used.
306
396
 *
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
310
 
 * is on Windows).
 
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).
311
400
 *
312
401
 * Returns: The top directory for GIMP config files.
313
402
 **/
317
406
  static gchar *gimp_sysconf_dir = NULL;
318
407
 
319
408
  if (! gimp_sysconf_dir)
320
 
    gimp_sysconf_dir = gimp_env_get_dir ("GIMP2_SYSCONFDIR", SYSCONFDIR);
 
409
    {
 
410
      gchar *tmp = _gimp_reloc_find_etc_dir (SYSCONFDIR);
 
411
 
 
412
      gimp_sysconf_dir = gimp_env_get_dir ("GIMP2_SYSCONFDIR", tmp);
 
413
      g_free (tmp);
 
414
    }
321
415
 
322
416
  return gimp_sysconf_dir;
323
417
}
331
425
 * defined directory is used. On Win32, the installation directory as
332
426
 * deduced from the executable's name is used.
333
427
 *
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
337
 
 * is on Windows).
 
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).
338
431
 *
339
432
 * Returns: The top directory for GIMP plug_ins and modules.
340
433
 **/
344
437
  static gchar *gimp_plug_in_dir = NULL;
345
438
 
346
439
  if (! gimp_plug_in_dir)
347
 
    gimp_plug_in_dir = gimp_env_get_dir ("GIMP2_PLUGINDIR", PLUGINDIR);
 
440
    {
 
441
      gchar *tmp = _gimp_reloc_find_plugin_dir (PLUGINDIR);
 
442
 
 
443
      gimp_plug_in_dir = gimp_env_get_dir ("GIMP2_PLUGINDIR", tmp);
 
444
      g_free (tmp);
 
445
    }
348
446
 
349
447
  return gimp_plug_in_dir;
350
448
}
354
452
 *
355
453
 * Returns the name of the GIMP's application-specific gtkrc file.
356
454
 *
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
360
 
 * is on Windows).
 
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).
361
458
 *
362
459
 * Returns: The name of the GIMP's application-specific gtkrc file.
363
460
 **/
387
484
 * and *@path is replaced with a pointer to a new string with the
388
485
 * run-time prefix spliced in.
389
486
 *
390
 
 * On Unix, does nothing.
 
487
 * On Linux, it does the same thing, but only if BinReloc support is enabled.
 
488
 * On other Unices, it does nothing because those platforms don't have a
 
489
 * way to find out where our binary is.
391
490
 */
392
491
static void
393
492
gimp_path_runtime_fix (gchar **path)
403
502
       */
404
503
      p = *path;
405
504
      *path = g_strconcat (gimp_toplevel_directory (),
406
 
                           "\\",
407
 
                           *path + strlen (PREFIX "/"),
408
 
                           NULL);
 
505
                           "\\",
 
506
                           *path + strlen (PREFIX "/"),
 
507
                           NULL);
409
508
      g_free (p);
410
509
    }
411
510
  /* Replace forward slashes with backslashes, just for
421
520
  gchar *p = *path;
422
521
  if (!g_path_is_absolute (p))
423
522
    {
 
523
      *path = g_build_filename (gimp_toplevel_directory (), *path, NULL);
 
524
      g_free (p);
 
525
    }
 
526
#else
 
527
  gchar *p;
 
528
 
 
529
  if (strncmp (*path, PREFIX G_DIR_SEPARATOR_S,
 
530
               strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
 
531
    {
 
532
      /* This is a compile-time entry. Replace the path with the
 
533
       * real one on this machine.
 
534
       */
 
535
      p = *path;
424
536
      *path = g_build_filename (gimp_toplevel_directory (),
425
 
                                *path, NULL);
 
537
                                *path + strlen (PREFIX G_DIR_SEPARATOR_S),
 
538
                                NULL);
426
539
      g_free (p);
427
540
    }
428
541
#endif
440
553
 **/
441
554
GList *
442
555
gimp_path_parse (const gchar  *path,
443
 
                 gint          max_paths,
444
 
                 gboolean      check,
445
 
                 GList       **check_failed)
 
556
                 gint          max_paths,
 
557
                 gboolean      check,
 
558
                 GList       **check_failed)
446
559
{
447
560
  const gchar  *home;
448
561
  gchar       **patharray;
463
576
      GString *dir;
464
577
 
465
578
      if (! patharray[i])
466
 
        break;
 
579
        break;
467
580
 
468
581
#ifndef G_OS_WIN32
469
582
      if (*patharray[i] == '~')
470
 
        {
471
 
          dir = g_string_new (home);
472
 
          g_string_append (dir, patharray[i] + 1);
473
 
        }
 
583
        {
 
584
          dir = g_string_new (home);
 
585
          g_string_append (dir, patharray[i] + 1);
 
586
        }
474
587
      else
475
588
#endif
476
 
        {
477
 
          gimp_path_runtime_fix (&patharray[i]);
478
 
          dir = g_string_new (patharray[i]);
479
 
        }
 
589
        {
 
590
          gimp_path_runtime_fix (&patharray[i]);
 
591
          dir = g_string_new (patharray[i]);
 
592
        }
480
593
 
481
594
      if (check)
482
595
        exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);
483
596
 
484
597
      if (exists)
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));
488
601
 
489
602
      g_string_free (dir, TRUE);
490
603
    }
511
624
gchar *
512
625
gimp_path_to_str (GList *path)
513
626
{
514
 
  GString *str = NULL;
 
627
  GString *str    = NULL;
515
628
  GList   *list;
516
629
  gchar   *retval = NULL;
517
630
 
518
631
  for (list = path; list; list = g_list_next (list))
519
632
    {
520
 
      gchar *dir = (gchar *) list->data;
 
633
      gchar *dir = list->data;
521
634
 
522
635
      if (str)
523
 
        {
524
 
          g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
525
 
          g_string_append (str, dir);
526
 
        }
 
636
        {
 
637
          g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
 
638
          g_string_append (str, dir);
 
639
        }
527
640
      else
528
 
        {
529
 
          str = g_string_new (dir);
530
 
        }
 
641
        {
 
642
          str = g_string_new (dir);
 
643
        }
531
644
    }
532
645
 
533
646
  if (str)
574
687
 
575
688
  for (list = path; list; list = g_list_next (list))
576
689
    {
577
 
      gchar *dir = (gchar *) list->data;
 
690
      gchar *dir = list->data;
578
691
 
579
692
      /*  check if directory exists  */
580
 
      err = stat (dir, &filestat);
 
693
      err = g_stat (dir, &filestat);
581
694
 
582
695
      /*  this is tricky:
583
696
       *  if a file is e.g. owned by the current user but not user-writable,
586
699
       */
587
700
      if (!err && S_ISDIR (filestat.st_mode) &&
588
701
 
589
 
          ((filestat.st_mode & S_IWUSR) ||
590
 
 
591
 
           ((filestat.st_mode & S_IWGRP) &&
592
 
            (euid != filestat.st_uid)) ||
593
 
 
594
 
           ((filestat.st_mode & S_IWOTH) &&
595
 
            (euid != filestat.st_uid) &&
596
 
            (egid != filestat.st_gid))))
597
 
        {
598
 
          return g_strdup (dir);
599
 
        }
 
702
          ((filestat.st_mode & S_IWUSR) ||
 
703
 
 
704
           ((filestat.st_mode & S_IWGRP) &&
 
705
            (euid != filestat.st_uid)) ||
 
706
 
 
707
           ((filestat.st_mode & S_IWOTH) &&
 
708
            (euid != filestat.st_uid) &&
 
709
            (egid != filestat.st_gid))))
 
710
        {
 
711
          return g_strdup (dir);
 
712
        }
600
713
    }
601
714
 
602
715
  return NULL;
606
719
gimp_env_get_dir (const gchar *gimp_env_name,
607
720
                  const gchar *env_dir)
608
721
{
609
 
  const gchar *env;
610
 
 
611
 
  env = g_getenv (gimp_env_name);
 
722
  const gchar *env = g_getenv (gimp_env_name);
612
723
 
613
724
  if (env)
614
725
    {
615
726
      if (! g_path_is_absolute (env))
616
 
        g_error ("%s environment variable should be an absolute path.",
 
727
        g_error ("%s environment variable should be an absolute path.",
617
728
                 gimp_env_name);
618
729
 
619
730
      return g_strdup (env);
621
732
  else
622
733
    {
623
734
      gchar *retval = g_strdup (env_dir);
 
735
 
624
736
      gimp_path_runtime_fix (&retval);
 
737
 
625
738
      return retval;
626
739
    }
627
740
}