Debian Codegraph @

gtk/gtkquartz.c

raw symbols SCIP
1 /* gtkquartz.c: Utility functions used by the Quartz port
2 *
3 * Copyright (C) 2006 Imendio AB
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "config.h"
20
21 #include "gtkprivate.h"
22
23 #include <gdk/macos/gdkmacos.h>
24
25 #ifdef QUARTZ_RELOCATION
26
27 /* Bundle-based functions for various directories. These almost work
28 * even when the application isn’t in a bundle, because mainBundle
29 * paths point to the bin directory in that case. It’s a simple matter
30 * to test for that and remove the last element.
31 */
32
33 static const char *
34 get_bundle_path (void)
35 {
36 static char *path = NULL;
37
38 if (path == NULL)
39 {
40 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
41 char *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
42 char *base;
43 [pool drain];
44
45 base = g_path_get_basename (resource_path);
46 if (strcmp (base, "bin") == 0)
47 path = g_path_get_dirname (resource_path);
48 else
49 path = strdup (resource_path);
50
51 g_free (resource_path);
52 g_free (base);
53 }
54
55 return path;
56 }
57
58 const char *
59 _gtk_get_datadir (void)
60 {
61 static char *path = NULL;
62
63 if (path == NULL)
64 path = g_build_filename (get_bundle_path (), "share", NULL);
65
66 return path;
67 }
68
69 const char *
70 _gtk_get_libdir (void)
71 {
72 static char *path = NULL;
73
74 if (path == NULL)
75 path = g_build_filename (get_bundle_path (), "lib", NULL);
76
77 return path;
78 }
79
80 const char *
81 _gtk_get_localedir (void)
82 {
83 static char *path = NULL;
84
85 if (path == NULL)
86 path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
87
88 return path;
89 }
90
91 const char *
92 _gtk_get_sysconfdir (void)
93 {
94 static char *path = NULL;
95
96 if (path == NULL)
97 path = g_build_filename (get_bundle_path (), "etc", NULL);
98
99 return path;
100 }
101
102 const char *
103 _gtk_get_data_prefix (void)
104 {
105 return get_bundle_path ();
106 }
107
108 #endif /* QUARTZ_RELOCATION */